home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / em-xmkit.zip / DPMISPEC.TXT < prev    next >
Text File  |  1990-07-26  |  172KB  |  7,723 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.                         DOS PROTECTED MODE INTERFACE (DPMI)
  28.  
  29.                                     SPECIFICATION
  30.  
  31.  
  32.  
  33.                   Protected Mode API For DOS Extended Applications
  34.  
  35.                                     Version 0.9
  36.  
  37.                                Printed July 26, 1990
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.                                  TABLE OF CONTENTS
  74.  
  75.  
  76.             1. Introduction............................................1
  77.  
  78.             2. General Notes for Protected Mode Programs...............4
  79.                 2.1 Virtual DOS Environments...........................5
  80.                     2.1.1 No Virtualization............................5
  81.                     2.1.2 Partial Virtualization.......................5
  82.                     2.1.3 Complete Virtualization......................5
  83.                 2.2 Descriptor Management..............................6
  84.                 2.3 Interrupt Flag Management..........................7
  85.                 2.4 Interrupts.........................................8
  86.                     2.4.1 Hardware Interrupts..........................8
  87.                     2.4.2 Software Interrupts..........................9
  88.                 2.5 Virtual Memory and Page Locking...................10
  89.  
  90.             3. Mode and Stack Switching...............................11
  91.                 3.1 Stacks and Stack Switching........................12
  92.                     3.1.1 Protected Mode Stack........................12
  93.                     3.1.2 Locked Protected Mode Stack.................12
  94.                     3.1.3 Real Mode Stack.............................12
  95.                     3.1.4 DPMI Host Ring 0 Stack......................12
  96.                 3.2 Default Interrupt Reflection......................13
  97.                 3.3 Mode Switching....................................14
  98.                 3.4 State Saving......................................15
  99.  
  100.             4. Error Handling.........................................16
  101.  
  102.             5. Loading DPMI Clients and Extended Applications.........17
  103.                 5.1 Obtaining the Real to Protected Mode Switch Entry
  104.                 Point.................................................18
  105.                 5.2 Calling the Real to Protected Mode Switch Entry
  106.                 Point.................................................19
  107.  
  108.             6. Terminating A Protected Mode Program...................22
  109.  
  110.             7. Mode Detection.........................................23
  111.  
  112.             8. LDT Descriptor Management Services.....................24
  113.                 8.1 Allocate LDT Descriptors..........................25
  114.                 8.2 Free LDT Descriptor...............................26
  115.                 8.3 Segment to Descriptor.............................27
  116.                 8.4 Get Next Selector Increment Value.................28
  117.                 8.5 Reserved Subfunctions.............................29
  118.                 8.6 Get Segment Base Address..........................30
  119.                 8.7 Set Segment Base Address..........................31
  120.                 8.8 Set Segment Limit.................................32
  121.                 8.9 Set Descriptor Access Rights......................33
  122.                 8.10 Create Code Segment Alias Descriptor.............35
  123.                 8.11 Get Descriptor...................................36
  124.                 8.12 Set Descriptor...................................37
  125.                 8.13 Allocate Specific LDT Descriptor.................38
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.             9. DOS Memory Management Services.........................39
  140.                 9.1 Allocate DOS Memory Block.........................40
  141.                 9.2 Free DOS Memory Block.............................41
  142.                 9.3 Resize DOS Memory Block...........................42
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.             10. Interrupt Services....................................43
  206.                 10.1 Get Real Mode Interrupt Vector...................44
  207.                 10.2 Set Real Mode Interrupt Vector...................45
  208.                 10.3 Get Processor Exception Handler Vector...........46
  209.                 10.4 Set Processor Exception Handler Vector...........47
  210.                 10.5 Get Protected Mode Interrupt Vector..............50
  211.                 10.6 Set Protected Mode Interrupt Vector..............51
  212.  
  213.             11. Translation Services..................................52
  214.                 11.1 Simulate Real Mode Interrupt.....................55
  215.                 11.2 Call Real Mode Procedure With Far Return Frame...56
  216.                 11.3 Call Real Mode Procedure With Iret Frame.........57
  217.                 11.4 Allocate Real Mode Call-Back Address.............58
  218.                 11.5 Free Real Mode Call-Back Address.................62
  219.                 11.6 Get State Save/Restore Addresses.................63
  220.                 11.7 Get Raw Mode Switch Addresses....................65
  221.  
  222.             12. Get Version...........................................66
  223.  
  224.             13. Memory Management Services............................67
  225.                 13.1 Get Free Memory Information......................68
  226.                 13.2 Allocate Memory Block............................70
  227.                 13.3 Free Memory Block................................71
  228.                 13.4 Resize Memory Block..............................72
  229.  
  230.             14. Page Locking Services.................................73
  231.                 14.1 Lock Linear Region...............................74
  232.                 14.2 Unlock Linear Region.............................75
  233.                 14.3 Mark Real Mode Region as Pageable................76
  234.                 14.4 Relock Real Mode Region..........................77
  235.                 14.5 Get Page Size....................................78
  236.  
  237.             15. Demand Paging Performance Tuning Services.............79
  238.                 15.1 Reserved Subfunctions............................80
  239.                 15.2 Mark Page as Demand Paging Candidate.............81
  240.                 15.3 Discard Page Contents............................82
  241.  
  242.             16. Physical Address Mapping..............................83
  243.  
  244.             17. Virtual interrupt State Functions.....................84
  245.                 17.1 Get and Disable Virtual Interrupt State..........85
  246.                 17.2 Get and Enable Virtual Interrupt State...........86
  247.                 17.3 Get Virtual Interrupt State......................87
  248.  
  249.             18. Get Vendor Specific API Entry Point...................88
  250.  
  251.             19. Debug Register Support................................89
  252.                 19.1 Set Debug Watchpoint.............................90
  253.                 19.2 Clear Debug Watchpoint...........................91
  254.                 19.3 Get State of Debug Watchpoint....................92
  255.                 19.4 Reset Debug Watchpoint...........................93
  256.  
  257.             20. Other APIs............................................94
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.             21. Notes For DOS Extenders...............................95
  272.                 21.1 Initialization of  Extenders.....................96
  273.                 21.2 Installing API Extensions........................96
  274.                 21.3 Loading the Application Program..................96
  275.                 21.4 Providing API Extensions.........................97
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.                                   1. INTRODUCTION
  339.  
  340.  
  341.             The DOS Protected Mode Interface (DPMI) was defined to allow
  342.             DOS  programs   to  access   the  extended   memory  of   PC
  343.             architecture computers  while maintaining system protection.
  344.             DPMI defines  a specific  subset of  DOS and BIOS calls that
  345.             can be made by protected mode DOS programs.  It also defines
  346.             a new  interface via  software interrupt  31h that protected
  347.             mode programs  use to  allocate memory,  modify descriptors,
  348.             call real  mode software,  etc.   Any operating  system that
  349.             currently supports virtual DOS sessions should be capable of
  350.             supporting DPMI without affecting system security.
  351.  
  352.             Some DPMI  implementations can  execute  multiple  protected
  353.             mode programs  in independent  virtual machines.  Thus, DPMI
  354.             applications can  behave exactly like any other standard DOS
  355.             program and  can, for example, run in the background or in a
  356.             window  (if   the  environment   supports  these  features).
  357.             Programs that  run in  protected  mode  also  gain  all  the
  358.             benefits of  virtual memory and can run in 32-bit flat model
  359.             if desired.
  360.  
  361.             Throughout this  document, the  term "real mode" software is
  362.             used to  refer to  code that  runs in  the  low  1  megabyte
  363.             address space  and uses  segment:offset addressing.    Under
  364.             many implementations  of DPMI,  so called real mode software
  365.             is actually  executed in  virtual 8086 mode.  However, since
  366.             virtual 8086  mode is  a very  close approximation  of  real
  367.             mode, we will refer to it as real mode in this document.
  368.  
  369.             DPMI services are only available to protected mode programs.
  370.             Programs running  in real  mode can  not use these services.
  371.             Protected mode  programs must  use the  service described on
  372.             page 20  to enter  protected mode  before  calling  Int  31h
  373.             services.
  374.  
  375.             All Int 31h functions will modify flags and the AX register.
  376.             All other  registers  will  be  preserved  unless  they  are
  377.             specified as  return values.   Unsupported calls will return
  378.             with the  carry flag set.  Since Int 31h is set up as a trap
  379.             gate, the interrupt flag will not be modified by any Int 31h
  380.             calls  except  for  memory  management  and  interrupt  flag
  381.             management calls.   All  memory management  calls may enable
  382.             interrupts.  Interrupt flag management calls will modify the
  383.             interrupt flag  as specified  by the  call.    All  Int  31h
  384.             services are reentrant.
  385.  
  386.             Some implementations  of DPMI  can run 32-bit 80386 specific
  387.             programs.   DPMI functions  that take pointers as parameters
  388.             will use  the extended  32-bit registers  for  offsets  (for
  389.             example, ES:EDI  instead of  ES:DI) when running 32-bit mode
  390.  
  391.  
  392.  
  393.  
  394.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9         Page 1
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.             programs.   The high  word of  the 32-bit  registers will be
  404.             ignored when running 16-bit protected mode programs.
  405.  
  406.             DPMI services  are provided  by what  will be referred to as
  407.             the DPMI  host  program.    The  program(s)  that  use  DPMI
  408.             services are  called DPMI  clients.  Generally, DPMI clients
  409.             are two categories:
  410.  
  411.                  o    Extended Applications
  412.                  o    Applications that use DPMI directly
  413.  
  414.             It is  believed that most DPMI applications will be extended
  415.             applications.   Extended  applications  are  bound  with  an
  416.             extender that  is the actual DPMI client and the application
  417.             calls extender  services that  then are  translated  by  the
  418.             client into  DPMI calls.    The  advantage  of  an  extended
  419.             application over  one that  calls DPMI  services directly is
  420.             that generally an extender will support more than just DPMI.
  421.             In fact  it is recommended that extenders look for extension
  422.             services in the following order:
  423.  
  424.                  o    DPMI
  425.                  o    VCPI/EMS
  426.                  o    XMS
  427.                  o    Top-down (Int 15h)
  428.  
  429.             An extender  can provide  a single set of APIs to the actual
  430.             application and then translate them to the services that are
  431.             provided.   Where the  host extension services are "lacking"
  432.             in a  particular function  the extender  must  provide  that
  433.             function for the application.
  434.  
  435.             Figure 1  on page  3 shows a picture of how this works.  The
  436.             application code  sits on  top of  a set  of  base  extender
  437.             functions and  APIs.  The extender then has separate modules
  438.             for each  type of extension service and code to "fill in the
  439.             slack" where  services are lacking.  An example of a typical
  440.             extender service  is protected  mode program  loading.   The
  441.             actual shipped  application is the application code bound in
  442.             with the extender and all of its styles of client support.
  443.  
  444.             The host  support is  generally an  extension of the base OS
  445.             functions or  a device  driver used  to extend  the base  OS
  446.             functions.
  447.  
  448.             This document  is intended  to provide  a definition  of the
  449.             DPMI  services  that  a  DPMI  host  would  be  required  to
  450.             implement and that a DPMI client would use.
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9         Page 2
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.             Figure 1.  Application/Extender/Client/Host/OS structure
  472.  
  473.  
  474.             +----------------------------------------------------------+
  475.             |                                                          |
  476.             |  +----------------------------------------------------+  |
  477.             |  |                                                    |  |
  478.             |  |                  Application Code                  |  |
  479.             |  |                                                    |  |
  480.             |  +----------------------------------------------------+  |
  481.             |                                                          |
  482.             |  +----------------------------------------------------+  |
  483.             |  |           Extender Base (including APIs)           |  |
  484.             |  | -------------------------------------------------- |  |
  485.             |  |    DPMI                                            |  |
  486.             |  |   client                                           |  |
  487.             |  +------------+                                       |  |
  488.             |               |    VCPI                               |  |
  489.             |               |   client                              |  |
  490.             |               +------------+                          |  |
  491.             |                            |    XMS                   |  |
  492.             |                            |   client                 |  |
  493.             |                            +------------+             |  |
  494.             |                                         |  Top-down   |  |
  495.             |                                         |   client    |  |
  496.             |                                         +-------------+  |
  497.             |                                                          |
  498.             +----------------------------------------------------------+
  499.  
  500.                +------------+
  501.                |            |
  502.                |            |
  503.                |            |------------+
  504.                |            |            |
  505.                |    DPMI    |            |
  506.                |    host    |    VCPI    |------------+
  507.                |            |            |            |
  508.                |            |            |            |
  509.                |            |------------|    XMS     |-------------+
  510.                |            |    EMS     |            |  Top-down   |
  511.                |            |            |            |  (Int 15h)  |
  512.                +----------------------------------------------------+
  513.  
  514.                +----------------------------------------------------+
  515.                |                                                    |
  516.                |             Operating System (e.g. DOS)            |
  517.                |                                                    |
  518.                +----------------------------------------------------+
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9         Page 3
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.                     2. GENERAL NOTES FOR PROTECTED MODE PROGRAMS
  537.  
  538.  
  539.             There are  a few  basic differences  between real  mode  and
  540.             protected mode  that need  to be addressed to convert a real
  541.             mode program to run in protected mode.
  542.  
  543.             Programs run  at a  protection level that prevents them from
  544.             executing privileged  instructions such  as lgdt, lidt, etc.
  545.             The DPMI  interface is  the only method application programs
  546.             have for modifying system structures such as descriptors.
  547.  
  548.             While DPMI  defines a specific set of functions that will be
  549.             supported  by   all  implementations,  there  may  be  minor
  550.             differences  in  individual  implementations.    Programmers
  551.             should refer  to the notes for their DPMI implementation for
  552.             documentation on  detecting  the  presence  of  and  calling
  553.             vendor specific  extensions.   However, any application that
  554.             is written to adhere only to standard DPMI calls should work
  555.             correctly under all implementations of DPMI.
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9         Page 4
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.              2.1 Virtual DOS Environments
  603.  
  604.  
  605.             Many  DPMI   implementations  are  simulated  "virtual  DOS"
  606.             sessions.  In other words, the DOS interface and environment
  607.             presented  to  the  program  are  not  actually  the  native
  608.             interface of  the operating  system.   Hardware  interrupts,
  609.             I/O, and  processor exceptions  will be  virtualized by  the
  610.             operating system.   This  means, for  example, that  a  DPMI
  611.             program may  receive a simulated keyboard interrupt and read
  612.             simulated I/O from the keyboard controller ports.
  613.  
  614.             In these  environments, actual  hardware interrupts  will be
  615.             handled by  the operating  system.   The physical interrupts
  616.             will be  invisible to  the DPMI application program.  If the
  617.             operating system  so  chooses,  it  may  reflect  a  virtual
  618.             interrupt to  the DPMI  program.   The DPMI program does not
  619.             need to know, nor should it care, if this is the case.  From
  620.             the program's  point of  view, the  interrupt looks  exactly
  621.             like a  "real" interrupt.   The  operating system  will also
  622.             virtualize I/O  to the  interrupt controller  ports and  any
  623.             other simulated devices.
  624.  
  625.             There are basically three levels of virtualization that DPMI
  626.             implementations can provide:
  627.  
  628.             2.1.1 No Virtualization
  629.  
  630.             In general,  stand-alone single tasking DPMI implementations
  631.             will not  virtualize  any  hardware  devices.    These  hose
  632.             extension programs  will execute  as standard  DOS real mode
  633.             drivers or  programs.   Extenders  which  use  the  services
  634.             provided by these DPMI host drivers will translate protected
  635.             mode DOS  calls to  real mode  DOS calls.    Normally  these
  636.             extenders will  invoke DPMI services to return the processor
  637.             to real  mode (instead  of virtual  8086 mode)  when calling
  638.             DOS.
  639.  
  640.             2.1.2 Partial Virtualization
  641.  
  642.             Some environments  that execute  under DOS  will  virtualize
  643.             hardware devices,  provide virtual  memory, or provide other
  644.             services  that   require  virtualization  of  some  hardware
  645.             devices.   Under these  environments, DPMI applications will
  646.             always run  at a non-privileged ring (usually ring 3).  Some
  647.             or all  hardware interrupts will be virtualized, some or all
  648.             I/O  will   be  virtualized,   and  virtual  memory  may  be
  649.             supported.     Under  these  implementations,  page  locking
  650.             services  usually   must  be  used  to  lock  interrupt  and
  651.             exception handling code.
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9         Page 5
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.             2.1.3 Complete Virtualization
  668.  
  669.             These  environments   provide  a  completely  simulated  DOS
  670.             environment.  The native operating system is something other
  671.             than MS-DOS.   Under  these  implementations  of  DPMI,  all
  672.             devices will  be virtualized to some extent.  Normally, page
  673.             locking services  will be  ignored by  these implementations
  674.             since all physical device interrupt and I/O handling will be
  675.             performed by the operating system.  Programs will always run
  676.             at a non-privileged ring.
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9         Page 6
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.              2.2 Descriptor Management
  735.  
  736.  
  737.             Protected mode  code segments  can not  be modified.    This
  738.             requires programs  to allocate  an alias  data descriptor if
  739.             they need to store data in a code segment.
  740.  
  741.             Segment arithmetic  that works in real mode does not work in
  742.             protected mode.
  743.  
  744.             Some calls will return a range of descriptors.  For example,
  745.             if a  16-bit mode program allocates a block of memory larger
  746.             than  64K,   the  call  will  allocate  several,  contiguous
  747.             descriptors.   Each descriptor  will have a 64K limit except
  748.             for the  final descriptor  which  will  have  a  limit  that
  749.             contains the  remainder of  the block.  The call will return
  750.             the first  selector in  the array.    To  get  to  the  next
  751.             selector, your  program must  add the  value returned by Int
  752.             31h call 0003h (see page 32).
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9         Page 7
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.              2.3 Interrupt Flag Management
  801.  
  802.  
  803.             The popf  and iret  instructions may not modify the state of
  804.             the interrupt  flag since most DPMI implementations will run
  805.             programs with  IOPL < DPL.  Programs must execute cli or sti
  806.             to modify the interrupt flag state.
  807.  
  808.             This means  that the  following  code  sequence  will  leave
  809.             interrupts disabled:
  810.  
  811.                  ;
  812.                  ; (Assume interrupts are enabled at this point)
  813.                  ;
  814.                          pushf
  815.                          cli
  816.                          .
  817.                          .
  818.                          popf            ; Interrupts are still OFF!
  819.  
  820.             Note that since some implementations of DPMI will maintain a
  821.             virtual interrupt state for protected mode DOS programs, the
  822.             current value  of the  interrupt flag  may not  reflect  the
  823.             current virtual  interrupt state.   Protected  mode programs
  824.             should use the virtual interrupt state services to determine
  825.             the current interrupt flag state (see page 99).
  826.  
  827.             Since cli  and sti  are privileged  instructions, they  will
  828.             cause a  protection violation  and the  DPMI  provider  will
  829.             simulate the  instruction.  Because of the overhead involved
  830.             in processing  the exception,  cli and sti should be used as
  831.             little as possible.  In general, you should expect either of
  832.             these instructions to require at least 300 clocks.
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9         Page 8
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.              2.4 Interrupts
  867.  
  868.  
  869.             Protected mode  programs can hook both hardware and software
  870.             interrupts  using  the  DPMI  get  and  set  protected  mode
  871.             interrupt vector  functions (see  page 56).   All interrupts
  872.             from  hardware   devices  such  as  the  timer  or  keyboard
  873.             controller will  always be  reflected to  the protected mode
  874.             interrupt handler  first.   If the  protected  mode  handler
  875.             jumps to  or calls  the previous  interrupt handler then the
  876.             interrupt will be reflected to real mode.
  877.  
  878.             As in real mode, interrupt procedures can either service the
  879.             interrupt and  iret or they can chain to the next handler in
  880.             the interrupt chain by executing pushf/call or by jumping to
  881.             the next  handler.  The final handler for all protected mode
  882.             interrupts will reflect the interrupt to real mode.
  883.  
  884.             When an  interrupt is  reflected to real mode, the EAX, EBX,
  885.             ECX, EDX,  ESI, EDI,  EBP registers,  and flags  will all be
  886.             passed from  protected to  real mode unaltered.  The segment
  887.             registers  will  contain  undefined  values  unless  an  API
  888.             translator (such  as a  DOS or  BIOS translator)  explicitly
  889.             sets a  real mode segment register.  DPMI will automatically
  890.             provide a  real mode stack for interrupts that are reflected
  891.             to real mode.
  892.  
  893.  
  894.             2.4.1 Hardware Interrupts
  895.  
  896.             The interrupt controllers are mapped to the system's default
  897.             interrupts.   On an  IBM AT-compatible  system, for example,
  898.             the master  interrupt controller  is programmed  with a base
  899.             interrupt of  8 and  the slave controller has a base of 70h.
  900.             The virtualized  interrupt controllers  can be reprogrammed;
  901.             the base  setting may be examined in protected mode with Int
  902.             31h function 0400h.
  903.  
  904.             Hardware interrupt  procedures and  all of  their data  must
  905.             reside in  locked memory.   All  memory that  is touched  by
  906.             hardware interrupt  hooks must  be locked.  The handler will
  907.             always be  called on  a locked  stack.  See page 12 for more
  908.             details.
  909.  
  910.             As in real mode, hardware interrupt handlers are called with
  911.             interrupts disabled.    Since  iret  will  not  restore  the
  912.             interrupt flag, hardware interrupt hooks must execute an sti
  913.             before  executing   iret  or  else  interrupts  will  remain
  914.             disabled.
  915.  
  916.             Protected mode  hardware interrupt  handlers will  always be
  917.             called even  for interrupts  that occur  in real  mode.  The
  918.  
  919.  
  920.  
  921.  
  922.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9         Page 9
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.             last hook on the protected mode interrupt chain will reflect
  932.             the interrupt to real mode.
  933.  
  934.             Protected mode hardware interrupt handlers that need to call
  935.             software running  in real  mode must either be sure that the
  936.             real mode  software that  they are  calling will  not modify
  937.             segment registers  or they  must use  the state save service
  938.             (see page  74) to  save and  restore the  real mode  segment
  939.             registers.   However, any  interrupt handler  that  executes
  940.             completely in  protected mode,  or uses translation services
  941.             0300h, 0301h,  or 0302h  does not need to save the real mode
  942.             register state.   Therefore,  this is  not an issue for most
  943.             interrupt handlers.
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 10
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.             For compatibility  with older  systems, computers  with  two
  998.             interrupt controllers  have the  BIOS redirect  one  of  the
  999.             interrupts from  the slave  controller into the range of the
  1000.             master controller.   For example, devices jumpered for IRQ 2
  1001.             on IBM  AT-compatible computers  actually interrupt on IRQ 9
  1002.             (interrupt 71h).   In  real mode,  the BIOS on these systems
  1003.             will convert  interrupt 71h  to Int  0Ah and  EOI the  slave
  1004.             controller.   A protected  mode program that needs access to
  1005.             the redirected  interrupt may  use variations  on either  of
  1006.             these techniques:
  1007.  
  1008.                  1.   Hook the  target interrupt  in real  mode.    This
  1009.                       takes advantage of the built in redirection.  This
  1010.                       is robust  on systems  where  other  software  has
  1011.                       reprogrammed the  interrupt controllers,  or where
  1012.                       the slave interrupt controller may be absent.
  1013.  
  1014.                  2.   Hook  the   actual  interrupt  in  both  real  and
  1015.                       protected mode.   In  this case,  the program must
  1016.                       EOI  both   the   slave   and   master   interrupt
  1017.                       controllers since  the BIOS  will not get control.
  1018.                       This is  more efficient  in that there will not be
  1019.                       any unnecessary switches to real mode.
  1020.  
  1021.             2.4.2 Software Interrupts
  1022.  
  1023.             Most software  interrupts executed  in real mode will not be
  1024.             reflected to  the protected  mode interrupt hooks.  However,
  1025.             some software  interrupts are  also reflected  to  protected
  1026.             mode programs when they are called in real mode.  These are:
  1027.  
  1028.  
  1029.                        INT            DESCRIPTION
  1030.  
  1031.                        1Ch    BIOS timer tick interrupt
  1032.                        23h    DOS Ctrl+C interrupt
  1033.                        24h    DOS critical error interrupt
  1034.  
  1035.  
  1036.             Programs should  not terminate  during interrupts  that were
  1037.             reflected from  real mode.   Terminating the program at this
  1038.             point may prevent the DPMI host from cleaning up properly.
  1039.  
  1040.             Of all software interrupts, only Ints 00h-07h will be called
  1041.             with virtual interrupts disabled.  For these interrupts, the
  1042.             handler should  return with  interrupts enabled.   All other
  1043.             interrupts will not modify the interrupt flag state.
  1044.  
  1045.             Since most  software interrupts  that are  executed in  real
  1046.             mode are  not reflected  to protected  mode interrupt hooks,
  1047.             programs would  be required to install a real mode interrupt
  1048.             hook to monitor these interrupts.
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 11
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.              2.5 Virtual Memory and Page Locking
  1065.  
  1066.  
  1067.             Many implementations  of DPMI  support virtual  memory.   In
  1068.             these environments,  it will be necessary to lock any memory
  1069.             that can  be touched while executing inside of DOS.  This is
  1070.             necessary because  it may  not be possible for the operating
  1071.             system to demand load a page if DOS is busy.
  1072.  
  1073.             Some DPMI implementations will not call DOS to read or write
  1074.             virtual memory  to disk  and under these implementations the
  1075.             page locking services may be ignored.  Since the entire DPMI
  1076.             session is  virtualized, a  page fault can be handled at any
  1077.             point while  executing the  program.    However,  under  all
  1078.             implementations, DPMI  applications  should  lock  interrupt
  1079.             code and  data.   The lock  calls will always return success
  1080.             under implementations that ignore these calls.
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 12
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.  
  1130.                             3. MODE AND STACK SWITCHING
  1131.  
  1132.  
  1133.             This section  contains an  overview of how DPMI hosts switch
  1134.             between protected  and real mode and handle stack switching.
  1135.             It is  important to  understand the host maintains the state
  1136.             of the client to prevent overwriting stack data or modifying
  1137.             segment registers.
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 13
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.              3.1 Stacks and Stack Switching
  1197.  
  1198.  
  1199.             Every  DPMI   task  runs  on  four  different  stacks:    An
  1200.             application ring  protected mode  stack, a  locked protected
  1201.             mode stack, a real mode stack, and a DPMI host ring 0 stack.
  1202.  
  1203.             The protected  mode stack  is the  one the  DPMI client  was
  1204.             running on  when it  switched into protected mode by calling
  1205.             the protected  mode entry  point (although  the  client  can
  1206.             switch to  another protected  mode stack  if desired).   The
  1207.             locked protected  mode stack  is provided by the DPMI server
  1208.             and  is   used  for   simulating  hardware   interrupts  and
  1209.             processing real mode call-backs.  The DPMI host provides the
  1210.             real mode  stack, which  is usually located in the data area
  1211.             provided by the client.  The ring 0 stack is only accessible
  1212.             by the  DPMI host.   However,  this stack  may contain state
  1213.             information about the currently running program.
  1214.  
  1215.  
  1216.             3.1.1 Protected Mode Stack
  1217.  
  1218.             This is  the stack that the client uses for normal execution
  1219.             in protected  mode.   The protected  mode stack  of  a  DPMI
  1220.             client can  be unlocked  if desired.    Software  interrupts
  1221.             executed in protected mode will be reflected on this stack.
  1222.  
  1223.             3.1.2 Locked Protected Mode Stack
  1224.  
  1225.             During hardware  interrupts, Int  1Ch,  Int  23h,  Int  24h,
  1226.             exceptions, and  real mode  call-back handling  in protected
  1227.             mode, the  DPMI will  host automatically  switch to a locked
  1228.             protected mode  stack.   When the interrupt or call returns,
  1229.             the host  will return  to the original protected mode stack.
  1230.             Note that  there is  only one,  4K, locked stack provided by
  1231.             the host.  The stack will be switched onto the first time an
  1232.             interrupt or  call is  reflected to protected mode, and will
  1233.             be switched  away from  when the client returns.  Subsequent
  1234.             nested interrupts  or calls  will not  cause a stack switch.
  1235.             Software interrupts do not automatically switch stacks.
  1236.  
  1237.             3.1.3 Real Mode Stack
  1238.  
  1239.             The DPMI host will provide the client with a real mode stack
  1240.             that is  at least  200h bytes  in size  and will  always  be
  1241.             locked.   Interrupts that  are reflected  into real mode, as
  1242.             well as  calls made  using the translation services, will be
  1243.             reflected on  this stack.  DPMI hosts will not automatically
  1244.             switch stacks for hardware interrupt processing in real mode
  1245.             since DOS performs this function automatically.
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 14
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.             3.1.4 DPMI Host Ring 0 Stack
  1262.  
  1263.             DPMI hosts  will normally  have a stack associated with each
  1264.             DPMI task.   The DPMI client will not be able to access this
  1265.             stack in  any way -- it is used by the host for execution at
  1266.             ring 0 to handle interrupts and exceptions.  This stack will
  1267.             sometimes be used to store state information while switching
  1268.             modes.   For example,  the original  SS:ESP of the protected
  1269.             mode program  could be  saved on  the ring 0 stack while the
  1270.             DPMI host switches onto the locked protected mode stack.
  1271.  
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 15
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.              3.2 Default Interrupt Reflection
  1329.  
  1330.  
  1331.             DPMI hosts  provide interrupt  vectors  for  all  100h  (256
  1332.             decimal) interrupts  for protected  mode clients.   When the
  1333.             DPMI client initializes, all interrupt vectors will point to
  1334.             code that  will automatically  reflect the interrupt to real
  1335.             mode (except  for Int  31h and  Int 21h,  AH=4Ch).   When  a
  1336.             default interrupt  reflection handler  is executed  it  will
  1337.             switch to real mode, preserving the EAX, EBX, ECX, EDX, ESI,
  1338.             EDI, and  EBP registers and flags, and reflect the interrupt
  1339.             in real  mode.   When the  real mode  interrupt returns, the
  1340.             default  interrupt  reflection  code  will  switch  back  to
  1341.             protected mode  and return  with the modified values of EAX,
  1342.             EBX, ECX,  EDX, ESI, EDI, EBP, and flags.  Segment registers
  1343.             and the  stack pointer  will not  be passed  between  modes.
  1344.             Therefore, any  API that  passes pointers  or information in
  1345.             segment registers  will need  to  be  translated  by  a  DOS
  1346.             extender.
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 16
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.              3.3 Mode Switching
  1395.  
  1396.  
  1397.             There are  three different  ways a  client can  force a mode
  1398.             switch between protected and real mode:
  1399.  
  1400.                  o    Execute the default interrupt reflection handler
  1401.                  o    Use the  translation services  to call  real  mode
  1402.             code
  1403.                  o    Use a  real mode  call-back to switch from real to
  1404.             protected mode
  1405.                  o    Use the raw mode switch functions
  1406.  
  1407.             All mode switches except for the raw mode switches will save
  1408.             some information  on the  DPMI host's  ring 0  stack.   This
  1409.             means that  programs should  not terminate  while in  nested
  1410.             mode switches  unless they  are using the raw mode switching
  1411.             services.  However, even programs that use raw mode switches
  1412.             should not attempt to terminate from a hardware interrupt or
  1413.             exception handler  since the  DPMI host  performs  automatic
  1414.             mode and stack switching to provide these services.
  1415.  
  1416.  
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 17
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.              3.4 State Saving
  1461.  
  1462.  
  1463.             Because DPMI  hosts switch  stacks automatically across mode
  1464.             switches,  it  is  sometimes  necessary  to  use  the  state
  1465.             save/restore functions  while  using  the  raw  mode  switch
  1466.             services.  The host will maintain information on the "other"
  1467.             mode's current  state.   This information  will include  the
  1468.             CS:(E)IP, SS:(E)SP,  and segment register values.  Since the
  1469.             DPMI client  has no  way to directly access these values, it
  1470.             will need to call the state saving functions when performing
  1471.             nested mode switches.
  1472.  
  1473.             For example,  during hardware interrupts, the DPMI host will
  1474.             preserve the  real mode's  segment  registers,  CS:EIP,  and
  1475.             SS:ESP on the ring 0 stack.  However, they are not pushed on
  1476.             any stack  in the  VM --  They are  only visible  at ring 0.
  1477.             When the  raw mode  switch functions  are called  they  will
  1478.             overwrite the information saved by the host.  At this point,
  1479.             the program  would return  to the  wrong  address  when  the
  1480.             interrupt returned.   For  more information on state saving,
  1481.             refer to the documentation on page 74.
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 18
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.  
  1526.                                  4. ERROR HANDLING
  1527.  
  1528.  
  1529.             Most Int  31h calls  can fail.   The  DPMI 0.9 specification
  1530.             does not  specify error return codes for most calls.  When a
  1531.             call fails  it will  set the  carry flag and return with the
  1532.             value in AX unmodified unless otherwise specified.  However,
  1533.             future DPMI  implementations will  return error codes in the
  1534.             AX register.   All  specific error  codes will have the high
  1535.             bit (bit  15) set.  If a function returns with carry set and
  1536.             the high  bit of AX clear, it should be treated as a general
  1537.             failure.   Specific error  codes will allow programs running
  1538.             under  future   DPMI  implementations  to  take  appropriate
  1539.             corrective action in some cases.
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 19
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.                  5. LOADING DPMI CLIENTS AND EXTENDED APPLICATIONS
  1593.  
  1594.  
  1595.             All DPMI  applications begin  execution in  real mode.    An
  1596.             application must  run first  as a  standard  real  mode  DOS
  1597.             program but it can switch to protected execution by making a
  1598.             few simple calls.
  1599.  
  1600.             DPMI does not define an executable file format for protected
  1601.             mode programs.   Instead,  programs must  provide their  own
  1602.             mechanism for loading and fixing up protected mode code.
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 20
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.  
  1658.              5.1 Obtaining the Real to Protected Mode Switch Entry
  1659.              Point
  1660.  
  1661.  
  1662.                  This function  can be called in real mode to detect the
  1663.                  presence of DPMI services and to obtain an address that
  1664.                  can be used to begin execution in protected mode.
  1665.  
  1666.             To Call
  1667.  
  1668.                  AX = 1687h
  1669.                  Execute an Int 2Fh (not an Int 31h)
  1670.  
  1671.             Returns
  1672.  
  1673.                  If function was successful:
  1674.                  AX = 0
  1675.                  BX = Flags
  1676.                       Bit 0 = 1 if 32-bit programs are supported
  1677.                  CL = Processor type
  1678.                       02h = 80286
  1679.                       03h = 80386
  1680.                       04h = 80486
  1681.                  DH = DPMI major version number
  1682.                  DL = DPMI minor version number
  1683.                  SI =  Number  of  paragraphs  required  for  DPMI  host
  1684.                       private data (may be 0)
  1685.                  ES:DI = Address of procedure to call to enter protected
  1686.                       mode
  1687.  
  1688.                  If function was not successful:
  1689.                  AX != 0
  1690.  
  1691.             Programmer's Notes
  1692.  
  1693.                  o    This  function   does  not   perform  the   actual
  1694.                       transition into  protected mode.  You need to call
  1695.                       the address  returned in  ES:DI, after  allocating
  1696.                       the private  data  area  for  the  DPMI  host,  to
  1697.                       perform the actual real to protected mode switch.
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 21
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.  
  1724.              5.2 Calling the Real to Protected Mode Switch Entry Point
  1725.  
  1726.  
  1727.                  After using  Int 2Fh  function  1687h,  to  obtain  the
  1728.                  protected mode  entry point,  the DPMI client must call
  1729.                  the entry point address as described in this section.
  1730.  
  1731.             To Call
  1732.  
  1733.                  AX = Flags
  1734.                       Bit 0 = 1 if program is a 32-bit application
  1735.                  ES =  Real mode  segment of  DPMI host data area.  This
  1736.                       must be  the size  of the data area returned in SI
  1737.                       from the previous function.  ES will be ignored if
  1738.                       the required data size is zero.
  1739.                  Call the  address returned  in ES:DI  by  the  previous
  1740.                       function
  1741.  
  1742.             Returns
  1743.  
  1744.                  If function was successful:
  1745.                  Carry flag is clear.
  1746.                  Program is now executing in protected mode.
  1747.                  CS =  16-bit selector  with base  of real mode CS and a
  1748.                       64K limit
  1749.                  SS = Selector with base of real mode SS and a 64K limit
  1750.                  DS = Selector with base of real mode DS and a 64K limit
  1751.                  ES = Selector to program's PSP with a 100h byte limit
  1752.                  FS and GS = 0 (if running on an 80386 or 80486)
  1753.                  If the program is a 32-bit application the high word of
  1754.                       ESP will be 0
  1755.                  All other registers are preserved
  1756.  
  1757.                  If function was not successful:
  1758.                  Carry flag is set.
  1759.                  Program is executing in real mode
  1760.  
  1761.             Programmer's Notes
  1762.  
  1763.                  o    Once in protected mode, all Int 31h calls that are
  1764.                       supported by DPMI can be called.
  1765.                  o    To terminate  the program, execute an Int 21h with
  1766.                       AH=4Ch and  AL=Error code.   This  is the standard
  1767.                       DOS exit  function.   Do not  use  any  other  DOS
  1768.                       termination call -- Only AH=4Ch is supported under
  1769.                       DPMI.
  1770.                  o    Under  different   implementations  of   DPMI  the
  1771.                       privilege ring of a program will change.  Programs
  1772.                       should make no assumptions about the ring at which
  1773.                       they  will   run.     When  creating  descriptors,
  1774.                       programs should  set the  DPL of the descriptor to
  1775.                       the same  ring as their initial code segment.  Use
  1776.                       the lar  instruction to  determine the  protection
  1777.  
  1778.  
  1779.  
  1780.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 22
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.                       ring  of   your  program's   code  segment.    All
  1790.                       descriptors created  by your program should be set
  1791.                       to the same protection level.
  1792.                  o    Programs  that   specify  that   they  are  32-bit
  1793.                       applications will initially run with a 16-bit code
  1794.                       segment.   Stack and  data  selectors  for  32-bit
  1795.                       programs will be 32-bit (the Big bit will be set).
  1796.                       However, all  Int 31h  calls will  require  48-bit
  1797.                       pointers even  though the  program is running in a
  1798.                       16-bit code segment.
  1799.                  o    Unless you have explicitly enabled the A20 address
  1800.                       line through the XMS interface, do not assume that
  1801.                       memory from  1Mb to  1Mb+64K-16 (the  High  Memory
  1802.                       Area) is  addressable once your program is running
  1803.                       in protected  mode.   If you  want to  be able  to
  1804.                       access the  HMA  then  you  must  enable  the  A20
  1805.                       through XMS  before entering  protected mode.  XMS
  1806.                       calls are  not supported  in protected mode.  Note
  1807.                       that  this   restriction  is  only  important  for
  1808.                       software that wishes to access the HMA.  Under all
  1809.                       implementations of  DPMI the  physical A20 address
  1810.                       line  will   always  be  enabled  while  executing
  1811.                       protected mode code.  However, some 80386 specific
  1812.                       DPMI implementations simulate 1Mb address wrap for
  1813.                       compatibility   reasons.      Under   these   DPMI
  1814.                       implementations, the  HMA will  not be  accessible
  1815.                       unless  the   A20  is   enabled  through  the  XMS
  1816.                       interface.
  1817.                  o    The environment  pointer in  the current program's
  1818.                       PSP  will   automatically  be   converted   to   a
  1819.                       descriptor.   If you  want to  free the  program's
  1820.                       environment memory, you must do so before entering
  1821.                       protected mode.   In  this case,  the  environment
  1822.                       pointer  descriptor  will  point  to  garbage  and
  1823.                       should not  be used.   The  DPMI client may change
  1824.                       the environment  pointer in the PSP after entering
  1825.                       protected mode  but it  must  restore  it  to  the
  1826.                       selector  created   by  the   DPMI   host   before
  1827.                       terminating.
  1828.                  o    The caller  is allowed  to modify  or free the DS,
  1829.                       SS, and  CS descriptors  allocated by  this  call.
  1830.                       You  may   not  modify   the  PSP   descriptor  or
  1831.                       environment pointer  descriptor in  the PSP.   See
  1832.                       page 30 for information on freeing descriptors.
  1833.                  o    Note that if DS=SS on entry to this call then only
  1834.                       one descriptor  will be  allocated for both DS and
  1835.                       SS.  In this case, for example, if you changed the
  1836.                       base of  the DS  descriptor you  would also change
  1837.                       the base of the stack segment.
  1838.                  o    For some hosts it may be a good idea for protected
  1839.                       mode programs  to use some or all of the real mode
  1840.                       memory allocated  to the  real mode program by DOS
  1841.                       for protected  mode code  or data.  Protected mode
  1842.                       programs that  use memory  in the first 1Mb should
  1843.  
  1844.  
  1845.  
  1846.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 23
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.                       mark the  memory as  pageable using Int 31h 0602h.
  1856.                       See page 90 for details.
  1857.  
  1858.  
  1859.  
  1860.  
  1861.  
  1862.  
  1863.  
  1864.  
  1865.  
  1866.  
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 24
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.             Example Code
  1922.  
  1923.                  ;
  1924.                  ; Get the entry point address and save it
  1925.                  ;
  1926.                          mov     ax, 1687h
  1927.                          int     2Fh
  1928.                          test    ax, ax
  1929.                          jnz     Cant_Enter_PMode
  1930.                          mov     [PMode_Entry_Seg], es
  1931.                          mov     [PMode_Entry_Off], di
  1932.  
  1933.                  ;
  1934.                  ; Allocate memory for use by DOS extender if necessary
  1935.                  ; NOTE:  This code assumes that the program has already
  1936.                  ;        shrunk its memory block so that the DOS
  1937.                  ;        memory allocation call will work
  1938.                  ;
  1939.                          test    si, si
  1940.                          jz      Enter_PMode_Now
  1941.                          mov     bx, si
  1942.                          mov     ah, 48h
  1943.                          int     21h
  1944.                          jc      Cant_Enter_PMode
  1945.                          mov     es, ax
  1946.  
  1947.                  ;
  1948.                  ; Enter protected mode as a 16-bit program
  1949.                  ;
  1950.                  Enter_PMode_Now:
  1951.                          xor     ax, ax
  1952.                          call    DWORD PTR [PMode_Entry_Off]
  1953.                          jc      Cant_Enter_PMode
  1954.  
  1955.                  ;
  1956.                  ; The program is running in protected mode now!
  1957.                  ; Protected mode initialization code would go here.
  1958.                  ; Mark program's real mode memory as pageable, etc.
  1959.                  ;
  1960.                          .
  1961.                          .
  1962.                          .
  1963.  
  1964.                  ;
  1965.                  ; Quit the program and return to real mode DOS
  1966.                  ;
  1967.                          mov     ax, 4C00h
  1968.                          int     21h
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 25
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.  
  1988.                       6. TERMINATING A PROTECTED MODE PROGRAM
  1989.  
  1990.  
  1991.             To terminate  a protected  mode program  execute an  Int 21h
  1992.             with AH=4Ch in protected mode.  You can return an error code
  1993.             in the  AL register.  This is the standard DOS terminate API
  1994.             but it  must be executed in protected mode to allow the DPMI
  1995.             host to  clean up  any data  structures associated  with the
  1996.             protected mode program.
  1997.  
  1998.             Programs should not be terminated from a hardware interrupt,
  1999.             exception handler,  or real mode call-back.  Programs should
  2000.             only be  terminated from  their main  thread of execution to
  2001.             allow the  DPMI host  to clean  up properly.   However,  DOS
  2002.             extenders that use the raw mode switch services for all mode
  2003.             transitions can  execute the  terminate call after switching
  2004.             from real to protected mode.
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 26
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053.  
  2054.                                  7. MODE DETECTION
  2055.  
  2056.  
  2057.             It is possible to write a program or library that can run in
  2058.             either real or protected mode.  This function is supplied so
  2059.             that bimodal  code can  detect at  run time  whether  it  is
  2060.             running under  protected mode.    Code  that  only  runs  in
  2061.             protected mode does not need to perform this test.
  2062.  
  2063.             To Call
  2064.  
  2065.                  AX = 1686h
  2066.                  Execute an Int 2Fh (not an Int 31h)
  2067.  
  2068.             Returns
  2069.  
  2070.                  If executing in protected mode under DPMI:
  2071.                  AX = 0
  2072.  
  2073.                  If executing in real mode or not under DPMI then:
  2074.                  AX != 0
  2075.  
  2076.             Programmer's Notes
  2077.  
  2078.                  o    This call  will return  AX = 0  when the caller is
  2079.                       running in protected mode.  It will return AX non-
  2080.                       zero even  when running  under  environments  that
  2081.                       support DPMI  if the  caller is  in real  (virtual
  2082.                       8086) mode.    See  page  20  for  information  on
  2083.                       entering protected mode.
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 27
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.  
  2119.  
  2120.                        8. LDT DESCRIPTOR MANAGEMENT SERVICES
  2121.  
  2122.  
  2123.             The LDT  descriptor management  services provide  interfaces
  2124.             for allocating,  freeing, creating,  locking  and  unlocking
  2125.             protected mode  descriptors  in  the  current  task's  Local
  2126.             Descriptor Table (LDT).
  2127.  
  2128.  
  2129.  
  2130.  
  2131.  
  2132.  
  2133.  
  2134.  
  2135.  
  2136.  
  2137.  
  2138.  
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 28
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.  
  2185.  
  2186.              8.1 Allocate LDT Descriptors
  2187.  
  2188.  
  2189.                  This  function   is  used   to  allocate  one  or  more
  2190.                  descriptors from  the  task's  Local  Descriptor  Table
  2191.                  (LDT).  The descriptor(s) allocated must be initialized
  2192.                  by the application.
  2193.  
  2194.             To Call
  2195.  
  2196.                  AX = 0000h
  2197.                  CX = Number of descriptors to allocate
  2198.  
  2199.             Returns
  2200.  
  2201.                  If function was successful:
  2202.                  Carry flag is clear.
  2203.                  AX = Base selector
  2204.  
  2205.                  If function was not successful:
  2206.                  Carry flag is set.
  2207.  
  2208.             Programmer's Notes
  2209.  
  2210.                  o    If more than one descriptor was requested, AX will
  2211.                       contain  the   first  of  a  contiguous  array  of
  2212.                       descriptors.  You should add the value returned by
  2213.                       function 0003h  (see page  32) to  get to the next
  2214.                       selector in the array.
  2215.                  o    The descriptor  will be  set to present data type,
  2216.                       with a base and limit of zero.
  2217.                  o    It is up to the caller to fill in the descriptors.
  2218.                  o    The privilege  level of descriptors will match the
  2219.                       application's code  segment privilege level.  When
  2220.                       modifying descriptors,  always set  the DPL to the
  2221.                       same  privilege   ring  as   your  program's  code
  2222.                       segment.  Use the lar instruction to determine the
  2223.                       privilege of a descriptor.
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 29
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.  
  2252.              8.2 Free LDT Descriptor
  2253.  
  2254.  
  2255.                  This function  is used  to free  descriptors that  were
  2256.                  allocated  through   the   Allocate   LDT   Descriptors
  2257.                  function.
  2258.  
  2259.             To Call
  2260.  
  2261.                  AX = 0001h
  2262.                  BX = Selector to free
  2263.  
  2264.             Returns
  2265.  
  2266.                  If function was successful:
  2267.                  Carry flag is clear.
  2268.  
  2269.                  If function was not successful:
  2270.                  Carry flag is set.
  2271.  
  2272.             Programmer's Notes
  2273.  
  2274.                  o    Arrays of  descriptors are  freed by  calling this
  2275.                       function for each of the individual descriptors.
  2276.                  o    It is  valid to free the descriptors allocated for
  2277.                       the program's  initial CS,  DS,  and  SS.    Other
  2278.                       descriptors that  were not  allocated by  function
  2279.                       0000h should  never  be  freed  by  this  function
  2280.                       unless otherwise specified.
  2281.  
  2282.  
  2283.  
  2284.  
  2285.  
  2286.  
  2287.  
  2288.  
  2289.  
  2290.  
  2291.  
  2292.  
  2293.  
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 30
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316.  
  2317.  
  2318.              8.3 Segment to Descriptor
  2319.  
  2320.  
  2321.                  This function  is used  to convert  real mode  segments
  2322.                  into descriptors that are addressable by protected mode
  2323.                  programs.
  2324.  
  2325.             To Call
  2326.  
  2327.                  AX = 0002h
  2328.                  BX = Real mode segment address
  2329.  
  2330.             Returns
  2331.  
  2332.  
  2333.                  If function was successful:
  2334.                  Carry flag is clear.
  2335.                  AX = Selector mapped to real mode segment
  2336.  
  2337.                  If function was not successful:
  2338.                  Carry flag is set.
  2339.  
  2340.             Programmer's Notes
  2341.  
  2342.                  o    Multiple calls  to this  function  with  the  same
  2343.                       segment will return the same selector.
  2344.                  o    Descriptors created  by this function should never
  2345.                       be modified or freed.  For this reason, you should
  2346.                       use this  function sparingly.    If  your  program
  2347.                       needs to examine various real mode addresses using
  2348.                       the same selector you should allocate a descriptor
  2349.                       and change  the base  using the  Set Segment  Base
  2350.                       Address function instead of using this function.
  2351.                  o    The descriptor's limit will be set to 64K.
  2352.                  o    The intent  of this  function is to allow programs
  2353.                       easy access  to commonly  used real  mode segments
  2354.                       such as 40h and A000h.  Do not use this service to
  2355.                       obtain descriptors to private data areas.
  2356.  
  2357.  
  2358.  
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 31
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382.  
  2383.  
  2384.              8.4 Get Next Selector Increment Value
  2385.  
  2386.  
  2387.                  Some functions  such as  allocate LDT  descriptors  and
  2388.                  allocate  DOS   memory  can   return  more   than   one
  2389.                  descriptor.   You must  call this function to determine
  2390.                  the value  that must  be added  to a selector to access
  2391.                  the next descriptor in the array.
  2392.  
  2393.             To Call
  2394.  
  2395.                  AX = 0003h
  2396.  
  2397.             Returns
  2398.  
  2399.                  Carry flag clear (this function always succeeds)
  2400.                  AX = Value to add to get to next selector
  2401.  
  2402.             Programmer's Notes
  2403.  
  2404.                  o    Do not  make any  assumptions about the value this
  2405.                       function will return.
  2406.                  o    The increment  value returned  will be  a power of
  2407.                       two.
  2408.  
  2409.  
  2410.  
  2411.  
  2412.  
  2413.  
  2414.  
  2415.  
  2416.  
  2417.  
  2418.  
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424.  
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 32
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.  
  2447.  
  2448.  
  2449.  
  2450.              8.5 Reserved Subfunctions
  2451.  
  2452.  
  2453.             Functions 0004h  and 0005h  are reserved  and should  not be
  2454.             called.
  2455.  
  2456.  
  2457.  
  2458.  
  2459.  
  2460.  
  2461.  
  2462.  
  2463.  
  2464.  
  2465.  
  2466.  
  2467.  
  2468.  
  2469.  
  2470.  
  2471.  
  2472.  
  2473.  
  2474.  
  2475.  
  2476.  
  2477.  
  2478.  
  2479.  
  2480.  
  2481.  
  2482.  
  2483.  
  2484.  
  2485.  
  2486.  
  2487.  
  2488.  
  2489.  
  2490.  
  2491.  
  2492.  
  2493.  
  2494.  
  2495.  
  2496.  
  2497.  
  2498.  
  2499.  
  2500.  
  2501.  
  2502.  
  2503.  
  2504.  
  2505.  
  2506.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 33
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514.  
  2515.  
  2516.              8.6 Get Segment Base Address
  2517.  
  2518.  
  2519.                  This function returns the 32-bit linear base address of
  2520.                  the specified segment.
  2521.  
  2522.             To Call
  2523.  
  2524.                  AX = 0006h
  2525.                  BX = Selector
  2526.  
  2527.             Returns
  2528.  
  2529.                  If function was successful:
  2530.                  Carry flag is clear.
  2531.                  CX:DX = 32-bit linear base address of segment
  2532.  
  2533.                  If function was not successful:
  2534.                  Carry flag is set.
  2535.  
  2536.             Programmer's Notes
  2537.  
  2538.                  o    This function  will fail if the selector specified
  2539.                       in BX is invalid
  2540.  
  2541.  
  2542.  
  2543.  
  2544.  
  2545.  
  2546.  
  2547.  
  2548.  
  2549.  
  2550.  
  2551.  
  2552.  
  2553.  
  2554.  
  2555.  
  2556.  
  2557.  
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.  
  2572.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 34
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.  
  2579.  
  2580.  
  2581.  
  2582.              8.7 Set Segment Base Address
  2583.  
  2584.  
  2585.                  This function changes the 32-bit linear base address of
  2586.                  the specified selector.
  2587.  
  2588.             To Call
  2589.  
  2590.                  AX = 0007h
  2591.                  BX = Selector
  2592.                  CX:DX = 32-bit linear base address for segment
  2593.  
  2594.             Returns
  2595.  
  2596.                  If function was successful:
  2597.                  Carry flag is clear.
  2598.  
  2599.                  If function was not successful:
  2600.                  Carry flag is set.
  2601.  
  2602.             Programmer's Notes
  2603.  
  2604.                  o    This function  will fail if the selector specified
  2605.                       in BX is invalid.
  2606.                  o    Your program  should only  modify descriptors that
  2607.                       were   allocated    through   the   Allocate   LDT
  2608.                       Descriptors function.
  2609.                  o    The high  8 bits of the base address (contained in
  2610.                       CH) will  be ignored  by 16-bit implementations of
  2611.                       DPMI.   This is  true even  when running  on 80386
  2612.                       machines.
  2613.  
  2614.  
  2615.  
  2616.  
  2617.  
  2618.  
  2619.  
  2620.  
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626.  
  2627.  
  2628.  
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 35
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.  
  2645.  
  2646.  
  2647.  
  2648.              8.8 Set Segment Limit
  2649.  
  2650.  
  2651.                  This function sets the limit for the specified segment.
  2652.  
  2653.             To Call
  2654.  
  2655.                  AX = 0008h
  2656.                  BX = Selector
  2657.                  CX:DX = 32-bit segment limit
  2658.  
  2659.             Returns
  2660.  
  2661.                  If function was successful:
  2662.                  Carry flag is clear.
  2663.  
  2664.                  If function was not successful:
  2665.                  Carry flag is set.
  2666.  
  2667.  
  2668.             Programmer's Notes
  2669.  
  2670.                  o    This function  will fail if the selector specified
  2671.                       in BX  is invalid or the specified limit could not
  2672.                       be set.   16-bit  DPMI implementations can not set
  2673.                       segment limits  greater than  0FFFFh (64K)  so  CX
  2674.                       must be  zero when  calling  this  function  under
  2675.                       these implementations of DPMI.
  2676.                  o    Segment limits  greater than  1 meg  must be  page
  2677.                       aligned.     That  is,  limits  greater  than  one
  2678.                       megabyte must have the low 12 bits set.
  2679.                  o    Your program  should only  modify descriptors that
  2680.                       were   allocated    through   the   Allocate   LDT
  2681.                       Descriptors function.
  2682.                  o    To get  the limit  of a segment you should use the
  2683.                       instruction lsl  (load  segment  limit)  which  is
  2684.                       supported on  80286 and 80386 machines.  Note that
  2685.                       on 80386  machines you will need to use the 32-bit
  2686.                       form of  lsl   if the  segment has a limit greater
  2687.                       than 64K.
  2688.  
  2689.  
  2690.  
  2691.  
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  
  2697.  
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.  
  2704.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 36
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.  
  2711.  
  2712.  
  2713.  
  2714.              8.9 Set Descriptor Access Rights
  2715.  
  2716.  
  2717.                  This function allows a protected mode program to modify
  2718.                  the access rights and type fields of a descriptor.
  2719.  
  2720.             To Call
  2721.  
  2722.                  AX = 0009h
  2723.                  BX = Selector
  2724.                  CL = Access rights/type byte
  2725.                  CH =  80386 extended  access rights/type  byte  (32-bit
  2726.                       DPMI implementations only)
  2727.  
  2728.             Returns
  2729.  
  2730.                  If function was successful:
  2731.                  Carry flag is clear.
  2732.  
  2733.                  If function was not successful:
  2734.                  Carry flag is set.
  2735.  
  2736.             Programmer's Notes
  2737.  
  2738.                  o    This function  will fail if the selector specified
  2739.                       in BX is invalid.
  2740.                  o    Your program  should only  modify descriptors that
  2741.                       were   allocated    through   the   Allocate   LDT
  2742.                       Descriptors function.
  2743.                  o    To examine  the access  rights of a descriptor you
  2744.                       should  use   the  instruction  lar  (load  access
  2745.                       rights) which  is supported  on  80286  and  80386
  2746.                       machines.
  2747.                  o    The access  rights/type byte  passed in CL has the
  2748.                       following format:
  2749.  
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.  
  2770.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 37
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778.  
  2779.  
  2780.                       +-------------------------------+
  2781.                       | P |  DPL  | 1 |C/D|E/C|W/R| A |
  2782.                       +-------+-----------------------+
  2783.                         |     |     |   |   |   |   +- 0=>Not Accessed
  2784.                         |     |     |   |   |   |            1=>Accessed
  2785.                          |       |        |   |   |   +-- Data: 0=>Read,
  2786.                       1=>R/W
  2787.                          |      |     |   |   |               Code: Must
  2788.                       be 1 (readable)
  2789.                         |     |     |   |   +-- Data: 0=>Exp-up, 1=>Exp-
  2790.                       dn
  2791.                          |      |     |   |              Code: Must be 0
  2792.                       (non-conform)
  2793.                         |     |     |   +-- 0=>Data, 1=>Code
  2794.                         |     |     |
  2795.                         |     |     +-- Must be 1
  2796.                         |     |
  2797.                         |     +-- Must equal caller's CPL
  2798.                         |
  2799.                         +- 0=>Absent, 1=>Present
  2800.  
  2801.                       A  parameter   which  does   not  meet  the  above
  2802.                       requirements is  invalid, and  causes the function
  2803.                       to return with the carry flag set.
  2804.  
  2805.                  o    16-bit  DPMI   implementations  will   ignore  the
  2806.                       extended access rights/type byte passed in CH even
  2807.                       if it  is running on an 80386 system.  32-bit DPMI
  2808.                       implementations  interpret  the  CH  parameter  as
  2809.                       follows:
  2810.  
  2811.                       +-------------------------------+
  2812.                       | G |B/D| 0 |Avl|    Reserved   |
  2813.                       +-----------------------+-------+
  2814.                         |   |   |   |         +-- Ignored
  2815.                         |   |   |   +-- Can be 0 or 1
  2816.                         |   |   +-- Must be 0
  2817.                         |   +-- 0=>Default 16-bit, 1=>Default 32-bit
  2818.                         +- 0=>Byte Granular, 1=>Page Granular
  2819.                       
  2820.                       A  parameter   which  does   not  meet  the  above
  2821.                       requirements is  invalid, and  causes the function
  2822.                       to return with the carry flag set.
  2823.  
  2824.  
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.  
  2836.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 38
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.  
  2843.  
  2844.  
  2845.  
  2846.              8.10 Create Code Segment Alias Descriptor
  2847.  
  2848.  
  2849.                  This function  will create  a data  descriptor that has
  2850.                  the same  base and  limit as the specified code segment
  2851.                  descriptor.
  2852.  
  2853.             To Call
  2854.  
  2855.                  AX = 000Ah
  2856.                  BX = Code segment selector
  2857.  
  2858.             Returns
  2859.  
  2860.                  If function was successful:
  2861.                  Carry flag is clear.
  2862.                  AX = New data selector
  2863.  
  2864.                  If function was not successful:
  2865.                  Carry flag is set.
  2866.  
  2867.             Programmer's Notes
  2868.  
  2869.                  o    This function  will fail if the selector specified
  2870.                       in BX is not a code segment or is invalid.
  2871.                  o    Use the Free LDT Descriptor function to deallocate
  2872.                       the alias descriptor.
  2873.                  o    The code  segment alias  descriptor will not track
  2874.                       changes to  the code  descriptor.  In other words,
  2875.                       if an  alias descriptor  is created,  and then the
  2876.                       base or  limit of the code segment is changed, the
  2877.                       alias descriptor's base or limit would not change.
  2878.  
  2879.  
  2880.  
  2881.  
  2882.  
  2883.  
  2884.  
  2885.  
  2886.  
  2887.  
  2888.  
  2889.  
  2890.  
  2891.  
  2892.  
  2893.  
  2894.  
  2895.  
  2896.  
  2897.  
  2898.  
  2899.  
  2900.  
  2901.  
  2902.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 39
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.  
  2909.  
  2910.  
  2911.  
  2912.              8.11 Get Descriptor
  2913.  
  2914.  
  2915.                  This function  copies the  descriptor table entry for a
  2916.                  specified descriptor into an eight byte buffer.
  2917.  
  2918.             To Call
  2919.  
  2920.                  AX = 000Bh
  2921.                  BX = Selector
  2922.                  ES:(E)DI =  Pointer to an 8 byte buffer to receive copy
  2923.                       of descriptor
  2924.  
  2925.             Returns
  2926.  
  2927.                  If function was successful:
  2928.                  Carry flag is clear.
  2929.                  ES:(E)DI = Pointer to buffer that contains descriptor
  2930.  
  2931.                  If function was not successful:
  2932.                  Carry flag is set.
  2933.  
  2934.             Programmer's Notes
  2935.  
  2936.                  o    This function  will fail if the selector specified
  2937.                       in BX is invalid or unallocated.
  2938.                  o    32-bit programs  must use  ES:EDI to  point to the
  2939.                       buffer.  16-bit programs should use ES:DI.
  2940.  
  2941.  
  2942.  
  2943.  
  2944.  
  2945.  
  2946.  
  2947.  
  2948.  
  2949.  
  2950.  
  2951.  
  2952.  
  2953.  
  2954.  
  2955.  
  2956.  
  2957.  
  2958.  
  2959.  
  2960.  
  2961.  
  2962.  
  2963.  
  2964.  
  2965.  
  2966.  
  2967.  
  2968.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 40
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.  
  2975.  
  2976.  
  2977.  
  2978.              8.12 Set Descriptor
  2979.  
  2980.  
  2981.                  This function  copies an eight byte buffer into the LDT
  2982.                  entry for a specified descriptor.
  2983.  
  2984.             To Call
  2985.  
  2986.                  AX = 000Ch
  2987.                  BX = Selector
  2988.                  ES:(E)DI =  Pointer to  an 8 byte  buffer that contains
  2989.                       descriptor
  2990.  
  2991.             Returns
  2992.  
  2993.                  If function was successful:
  2994.                  Carry flag is clear.
  2995.  
  2996.                  If function was not successful:
  2997.                  Carry flag is set.
  2998.  
  2999.             Programmer's Notes
  3000.  
  3001.                  o    This function  will fail if the selector specified
  3002.                       in BX is invalid.
  3003.                  o    Your program  should only  modify descriptors that
  3004.                       were   allocated    through   the   Allocate   LDT
  3005.                       Descriptors function.
  3006.                  o    32-bit programs  must use  ES:EDI to  point to the
  3007.                       buffer.  16-bit programs should use ES:DI.
  3008.                  o    The type byte (byte 5) follows the same format and
  3009.                       restrictions as  the access  rights/type parameter
  3010.                       (in CL)  to Set  Descriptor Access  Rights.    The
  3011.                       extended type  byte  (byte  6)  follows  the  same
  3012.                       format and  restrictions as  the  extended  access
  3013.                       rights/type parameter  (in CH)  to Set  Descriptor
  3014.                       Access Rights, except the limit field may have any
  3015.                       value,  except   the  low  order  4  bits  (marked
  3016.                       "reserved") are  used to  set the  upper 4 bits of
  3017.                       the descriptor's limit.
  3018.  
  3019.  
  3020.  
  3021.  
  3022.  
  3023.  
  3024.  
  3025.  
  3026.  
  3027.  
  3028.  
  3029.  
  3030.  
  3031.  
  3032.  
  3033.  
  3034.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 41
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.  
  3041.  
  3042.  
  3043.  
  3044.              8.13 Allocate Specific LDT Descriptor
  3045.  
  3046.  
  3047.  
  3048.  
  3049.                  This function attempts to allocate a specific LDT
  3050.             descriptor.To Call
  3051.  
  3052.                  AX = 000Dh
  3053.                  BX = Selector
  3054.  
  3055.             Returns
  3056.  
  3057.                  If function was successful:
  3058.                  Carry flag is clear.
  3059.                  Descriptor has been allocated
  3060.  
  3061.                  If function was not successful:
  3062.                  Carry flag is set.
  3063.  
  3064.             Programmer's Notes
  3065.  
  3066.                  o    This function  will fail if the selector specified
  3067.                       in BX is in use or is not an LDT selector.
  3068.                  o    Use function 0001h to free the descriptor.
  3069.                  o    The first  10h (16  decimal) descriptors  must  be
  3070.                       reserved for  this function and may not be used by
  3071.                       the host.
  3072.                  o    If another  application has  already  loaded  then
  3073.                       some of these descriptors may be in use.
  3074.  
  3075.  
  3076.  
  3077.  
  3078.  
  3079.  
  3080.  
  3081.  
  3082.  
  3083.  
  3084.  
  3085.  
  3086.  
  3087.  
  3088.  
  3089.  
  3090.  
  3091.  
  3092.  
  3093.  
  3094.  
  3095.  
  3096.  
  3097.  
  3098.  
  3099.  
  3100.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 42
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107.  
  3108.  
  3109.  
  3110.                          9. DOS MEMORY MANAGEMENT SERVICES
  3111.  
  3112.  
  3113.             Some applications  require the ability to allocate memory in
  3114.             the real mode addressable 1 megabyte region.  These services
  3115.             allow protected  mode  applications  to  allocate  and  free
  3116.             memory that  is directly  addressable by  real mode software
  3117.             such as networks and DOS device drivers.  Often, this memory
  3118.             is used  in conjunction with the API translation services to
  3119.             call real  mode software  that is  not directly supported by
  3120.             DPMI.
  3121.  
  3122.  
  3123.  
  3124.  
  3125.  
  3126.  
  3127.  
  3128.  
  3129.  
  3130.  
  3131.  
  3132.  
  3133.  
  3134.  
  3135.  
  3136.  
  3137.  
  3138.  
  3139.  
  3140.  
  3141.  
  3142.  
  3143.  
  3144.  
  3145.  
  3146.  
  3147.  
  3148.  
  3149.  
  3150.  
  3151.  
  3152.  
  3153.  
  3154.  
  3155.  
  3156.  
  3157.  
  3158.  
  3159.  
  3160.  
  3161.  
  3162.  
  3163.  
  3164.  
  3165.  
  3166.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 43
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.  
  3173.  
  3174.  
  3175.  
  3176.              9.1 Allocate DOS Memory Block
  3177.  
  3178.  
  3179.                  This function  will allocate a block of memory from the
  3180.                  DOS free  memory pool.   It  returns both the real mode
  3181.                  segment and one or more descriptors that can be used by
  3182.                  protected mode applications to access the block.
  3183.  
  3184.             To Call
  3185.  
  3186.                  AX = 0100h
  3187.                  BX = Number of paragraphs (16 byte blocks) desired
  3188.  
  3189.             Returns
  3190.  
  3191.                  If function was successful:
  3192.                  Carry flag is clear.
  3193.                  AX = Initial real mode segment of allocated block
  3194.                  DX = Selector for allocated block
  3195.  
  3196.                  If function was not successful:
  3197.                  Carry flag is set.
  3198.                  AX = DOS error code:
  3199.                       07h  memory control blocks damaged
  3200.                       08h  insufficient memory  available to allocate as
  3201.                       requested
  3202.                  BX = Size of largest available block in paragraphs
  3203.  
  3204.             Programmer's Notes
  3205.  
  3206.                  o    If the size of the block requested is greater than
  3207.                       64K bytes (BX > 1000h) then contiguous descriptors
  3208.                       will be  allocated.  To access the next descriptor
  3209.                       for the  memory block  add  the  value  return  by
  3210.                       function 0003h (see page 32) to the base selector.
  3211.                       If more than one descriptor is allocated under 32-
  3212.                       bit DPMI  implementations, the  limit of the first
  3213.                       descriptor will  be set  to the size of the entire
  3214.                       block.   All subsequent  descriptors will  have  a
  3215.                       limit of 64K except for the final descriptor which
  3216.                       will have  a limit  of Block size MOD 64K.  16-bit
  3217.                       DPMI implementations  will always set the limit of
  3218.                       the first  descriptor to  64K even when running on
  3219.                       an 80386.
  3220.                  o    Your program should never modify or deallocate any
  3221.                       descriptors allocated  by this function.  The Free
  3222.                       DOS Memory  Block  function  will  deallocate  the
  3223.                       descriptors automatically
  3224.  
  3225.  
  3226.  
  3227.  
  3228.  
  3229.  
  3230.  
  3231.  
  3232.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 44
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.  
  3239.  
  3240.  
  3241.  
  3242.              9.2 Free DOS Memory Block
  3243.  
  3244.  
  3245.                  This function  frees memory  that was allocated through
  3246.                  the Allocate DOS Memory Block function.
  3247.  
  3248.             To Call
  3249.  
  3250.                  AX = 0101h
  3251.                  DX = Selector of block to free
  3252.  
  3253.             Returns
  3254.  
  3255.                  If function was successful:
  3256.                  Carry flag is clear.
  3257.  
  3258.                  If function was not successful:
  3259.                  Carry flag is set.
  3260.                  AX = DOS error code:
  3261.                       07h  memory control blocks damaged
  3262.                       09h  incorrect memory segment specified
  3263.  
  3264.             Programmer's Notes
  3265.  
  3266.                  o    All descriptors allocated for the memory block are
  3267.                       automatically freed  and therefore  should not  be
  3268.                       accessed once the block is freed by this function.
  3269.  
  3270.  
  3271.  
  3272.  
  3273.  
  3274.  
  3275.  
  3276.  
  3277.  
  3278.  
  3279.  
  3280.  
  3281.  
  3282.  
  3283.  
  3284.  
  3285.  
  3286.  
  3287.  
  3288.  
  3289.  
  3290.  
  3291.  
  3292.  
  3293.  
  3294.  
  3295.  
  3296.  
  3297.  
  3298.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 45
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.  
  3305.  
  3306.  
  3307.  
  3308.              9.3 Resize DOS Memory Block
  3309.  
  3310.  
  3311.                  This function  is used to grow or shrink a memory block
  3312.                  that was  allocated through  the  Allocate  DOS  Memory
  3313.                  Block function.
  3314.  
  3315.             To Call
  3316.  
  3317.                  AX = 0102h
  3318.                  BX = New block size in paragraphs
  3319.                  DX = Selector of block to modify
  3320.  
  3321.             Returns
  3322.  
  3323.                  If function was successful:
  3324.                  Carry flag is clear.
  3325.  
  3326.                  If function was not successful:
  3327.                  Carry flag is set.
  3328.                  AX = DOS error code:
  3329.                       07h  memory control blocks damaged
  3330.                       08h  insufficient memory  available to allocate as
  3331.                       requested
  3332.                       09h  incorrect memory segment specified
  3333.                  BX = Maximum block size possible in paragraphs
  3334.  
  3335.             Programmer's Notes
  3336.  
  3337.                  o    Growing a  memory block  is often  likely to  fail
  3338.                       since other  DOS block  allocations  will  prevent
  3339.                       increasing the  size of  the block.   Also, if the
  3340.                       size of a block grows past a 64K boundary then the
  3341.                       allocation will fail if the next descriptor in the
  3342.                       LDT is  not free.   Therefore,  this  function  is
  3343.                       usually only used to shrink a block.
  3344.                  o    Shrinking a  block may cause some descriptors that
  3345.                       were previously  allocated  to  the  block  to  be
  3346.                       freed.  For example shrinking a block from 140K to
  3347.                       120K would cause the third allocated descriptor to
  3348.                       be freed since it is no longer valid.  The initial
  3349.                       selector  will   remain  unchanged,  however,  the
  3350.                       limits  of  the  remaining  two  descriptors  will
  3351.                       change:  the first to 120K and the second to 56k.
  3352.  
  3353.  
  3354.  
  3355.  
  3356.  
  3357.  
  3358.  
  3359.  
  3360.  
  3361.  
  3362.  
  3363.  
  3364.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 46
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.  
  3371.  
  3372.  
  3373.  
  3374.                                10. INTERRUPT SERVICES
  3375.  
  3376.  
  3377.             These  services   allow  protected   mode  applications   to
  3378.             intercept  real  and  protected  mode  interrupts  and  hook
  3379.             processor exceptions.
  3380.  
  3381.  
  3382.  
  3383.  
  3384.  
  3385.  
  3386.  
  3387.  
  3388.  
  3389.  
  3390.  
  3391.  
  3392.  
  3393.  
  3394.  
  3395.  
  3396.  
  3397.  
  3398.  
  3399.  
  3400.  
  3401.  
  3402.  
  3403.  
  3404.  
  3405.  
  3406.  
  3407.  
  3408.  
  3409.  
  3410.  
  3411.  
  3412.  
  3413.  
  3414.  
  3415.  
  3416.  
  3417.  
  3418.  
  3419.  
  3420.  
  3421.  
  3422.  
  3423.  
  3424.  
  3425.  
  3426.  
  3427.  
  3428.  
  3429.  
  3430.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 47
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.  
  3437.  
  3438.  
  3439.  
  3440.              10.1 Get Real Mode Interrupt Vector
  3441.  
  3442.  
  3443.                  This function  returns the  value of the current task's
  3444.                  real mode interrupt vector for the specified interrupt.
  3445.  
  3446.             To Call
  3447.  
  3448.                  AX = 0200h
  3449.                  BL = Interrupt number
  3450.  
  3451.             Returns
  3452.  
  3453.                  Carry flag is clear.
  3454.                  CX:DX = Segment:Offset of real mode interrupt handler
  3455.  
  3456.             Programmer's Notes
  3457.  
  3458.                  o    The address  returned in  CX is  a segment,  not a
  3459.                       selector.   Therefore you  should not  attempt  to
  3460.                       place the  value returned  in CX  into  a  segment
  3461.                       register in protected mode or a general protection
  3462.                       fault may occur.
  3463.                  o    Note all 100h (256 decimal) interrupt vectors must
  3464.                       be supported by the DPMI host.
  3465.  
  3466.  
  3467.  
  3468.  
  3469.  
  3470.  
  3471.  
  3472.  
  3473.  
  3474.  
  3475.  
  3476.  
  3477.  
  3478.  
  3479.  
  3480.  
  3481.  
  3482.  
  3483.  
  3484.  
  3485.  
  3486.  
  3487.  
  3488.  
  3489.  
  3490.  
  3491.  
  3492.  
  3493.  
  3494.  
  3495.  
  3496.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 48
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.  
  3503.  
  3504.  
  3505.  
  3506.              10.2 Set Real Mode Interrupt Vector
  3507.  
  3508.  
  3509.                  This function sets the value of the current task's real
  3510.                  mode interrupt vector for the specified interrupt.
  3511.  
  3512.             To Call
  3513.  
  3514.                  AX = 0201h
  3515.                  BL = Interrupt number
  3516.                  CX:DX = Segment:Offset of real mode interrupt handler
  3517.  
  3518.             Returns
  3519.  
  3520.                  If function was successful:
  3521.                  Carry flag is clear.
  3522.  
  3523.                  If function was not successful:
  3524.                  Carry flag is set.
  3525.  
  3526.             Programmer's Notes
  3527.  
  3528.                  o    The address  passed in  CX must  be  a  real  mode
  3529.                       segment, not a selector.
  3530.                  o    If  the  interrupt  being  hooked  is  a  hardware
  3531.                       interrupt then  you must lock the segment that the
  3532.                       interrupt handler  runs in  as well  as any memory
  3533.                       the handler may touch at interrupt time.
  3534.                  o    The address contained in CX:DX must be a real mode
  3535.                       segment:offset, not a selector:offset.  This means
  3536.                       that the  code  for  the  interrupt  handler  must
  3537.                       either reside  in DOS  addressable memory  or  you
  3538.                       must use  a real mode call-back address.  Refer to
  3539.                       the section  on DOS  memory management services on
  3540.                       page 43 for information on allocating memory below
  3541.                       1 megabyte.   Information  on real  mode call back
  3542.                       addresses can be found on page 68.
  3543.  
  3544.  
  3545.  
  3546.  
  3547.  
  3548.  
  3549.  
  3550.  
  3551.  
  3552.  
  3553.  
  3554.  
  3555.  
  3556.  
  3557.  
  3558.  
  3559.  
  3560.  
  3561.  
  3562.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 49
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.  
  3569.  
  3570.  
  3571.  
  3572.              10.3 Get Processor Exception Handler Vector
  3573.  
  3574.  
  3575.                  This function  returns  the  CS:(E)IP  of  the  current
  3576.                  protected mode  exception  handler  for  the  specified
  3577.                  exception number.
  3578.  
  3579.             To Call
  3580.  
  3581.                  AX = 0202h
  3582.                  BL = Exception/fault number (00h-1Fh)
  3583.  
  3584.             Returns
  3585.  
  3586.                  If function was successful:
  3587.                  Carry flag is clear.
  3588.                  CX:(E)DX = Selector:Offset of exception handler
  3589.  
  3590.                  If function was not successful:
  3591.                  Carry flag is set.
  3592.                  The value passed in BL was invalid.
  3593.  
  3594.             Programmer's Notes
  3595.  
  3596.                  o    The value returned in CX is a valid protected mode
  3597.                       selector, not a real mode segment.
  3598.                  o    32-bit mode  programs will  be returned  a  32-bit
  3599.                       offset in the EDX register.
  3600.  
  3601.  
  3602.  
  3603.  
  3604.  
  3605.  
  3606.  
  3607.  
  3608.  
  3609.  
  3610.  
  3611.  
  3612.  
  3613.  
  3614.  
  3615.  
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621.  
  3622.  
  3623.  
  3624.  
  3625.  
  3626.  
  3627.  
  3628.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 50
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.  
  3635.  
  3636.  
  3637.  
  3638.              10.4 Set Processor Exception Handler Vector
  3639.  
  3640.  
  3641.                  This function  allows protected  mode  applications  to
  3642.                  intercept processor  exceptions that are not handled by
  3643.                  the DPMI  environment.   Programs may  wish  to  handle
  3644.                  exceptions such  as not  present segment  faults  which
  3645.                  would otherwise generate a fatal error.
  3646.  
  3647.                  Every exception is first examined by the protected mode
  3648.                  operating system.   If  it can not handle the exception
  3649.                  it  then   reflects  it   through  the  protected  mode
  3650.                  exception handler  chain.   The final  handler  in  the
  3651.                  chain may  either reflect the exception as an interrupt
  3652.                  (as would  happen in real mode) or it may terminate the
  3653.                  current program.
  3654.  
  3655.  
  3656.             To Call
  3657.  
  3658.                  AX = 0203h
  3659.                  BL = Exception/fault number (00h-1Fh)
  3660.                  CX:(E)DX = Selector:Offset of exception handler
  3661.  
  3662.             Returns
  3663.  
  3664.                  If function was successful:
  3665.                  Carry flag is clear.
  3666.  
  3667.                  If function was not successful:
  3668.                  Carry flag is set.
  3669.                  The value passed in BL was invalid.
  3670.  
  3671.             Programmer's Notes
  3672.  
  3673.                  o    The value  passed in  CX must be a valid protected
  3674.                       mode code selector, not a real mode segment.
  3675.                  o    32-bit mode  programs must  supply a 32-bit offset
  3676.                       in the  EDX register.   If  your handler chains to
  3677.                       the next  exception handler  it must do so using a
  3678.                       32-bit interrupt stack frame.
  3679.                  o    The handler  should  return  using  a  far  return
  3680.                       instruction.   The original SS:(E)SP, CS:(E)IP and
  3681.                       flags on  the stack, including the interrupt flag,
  3682.                       will be restored.
  3683.                  o    All  fault   stack  frames  have  an  error  code.
  3684.                       However,  the   error  code   is  only  valid  for
  3685.                       exceptions 08h, 0Ah, 0Bh, 0Ch, 0Dh, and 0Eh.
  3686.                  o    The  handler   must  preserve   and  restore   all
  3687.                       registers.
  3688.                  o    The exception  handler will  be called on a locked
  3689.                       stack with  interrupts disabled.  The original SS,
  3690.  
  3691.  
  3692.  
  3693.  
  3694.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 51
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.  
  3701.  
  3702.  
  3703.                       (E)SP,  CS,  and  (E)IP  will  be  pushed  on  the
  3704.                       exception handler stack frame.
  3705.                  o    The handler  must either  return from  the call by
  3706.                       executing a far return or jump to the next handler
  3707.                       in the  chain (which  will execute a far return or
  3708.                       chain to the next handler).
  3709.  
  3710.  
  3711.  
  3712.  
  3713.  
  3714.  
  3715.  
  3716.  
  3717.  
  3718.  
  3719.  
  3720.  
  3721.  
  3722.  
  3723.  
  3724.  
  3725.  
  3726.  
  3727.  
  3728.  
  3729.  
  3730.  
  3731.  
  3732.  
  3733.  
  3734.  
  3735.  
  3736.  
  3737.  
  3738.  
  3739.  
  3740.  
  3741.  
  3742.  
  3743.  
  3744.  
  3745.  
  3746.  
  3747.  
  3748.  
  3749.  
  3750.  
  3751.  
  3752.  
  3753.  
  3754.  
  3755.  
  3756.  
  3757.  
  3758.  
  3759.  
  3760.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 52
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.  
  3767.  
  3768.  
  3769.                  o    The procedure  can modify any of the values on the
  3770.                       stack   pertaining   to   the   exception   before
  3771.                       returning.  This can be used, for example, to jump
  3772.                       to a  procedure by  modifying  the  CS:IP  on  the
  3773.                       stack.   Note that  the procedure  must not modify
  3774.                       the far  return address  on the  stack --  it must
  3775.                       return to  the original  caller.   The caller will
  3776.                       then restore the flags, CS:(E)IP and SS:(E)SP from
  3777.                       the stack frame.
  3778.                  o    If the  DPMI client  does not handle an exception,
  3779.                       or jumps  to the  default exception  handler,  the
  3780.                       host will  reflect the  exception as  an interrupt
  3781.                       for  exceptions   0,  1,   2,  3,  4,  5,  and  7.
  3782.                       Exceptions 6,  and 8-1Fh  will be treated as fatal
  3783.                       errors and the client will be terminated.
  3784.                  o    Exception  handlers   will  only   be  called  for
  3785.                       exceptions that occur in protected mode.
  3786.  
  3787.  
  3788.  
  3789.  
  3790.  
  3791.  
  3792.  
  3793.  
  3794.  
  3795.  
  3796.  
  3797.  
  3798.  
  3799.  
  3800.  
  3801.  
  3802.  
  3803.  
  3804.  
  3805.  
  3806.  
  3807.  
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.  
  3814.  
  3815.  
  3816.  
  3817.  
  3818.  
  3819.  
  3820.  
  3821.  
  3822.  
  3823.  
  3824.  
  3825.  
  3826.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 53
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832.  
  3833.  
  3834.  
  3835.             Call-Back Stack Frames
  3836.  
  3837.                  Stack frame for 16-bit programs:
  3838.  
  3839.                       15       0
  3840.  
  3841.  
  3842.                           SS
  3843.  
  3844.                           SP
  3845.  
  3846.                         Flags
  3847.  
  3848.                           CS
  3849.  
  3850.                           IP
  3851.  
  3852.                        Err Code
  3853.  
  3854.  
  3855.                         Return
  3856.                           CS
  3857.  
  3858.                         Return
  3859.                           IP
  3860.  
  3861.                                  <-- SS:SP
  3862.  
  3863.                  Stack frame for 32-bit programs:
  3864.  
  3865.                  31            0
  3866.  
  3867.  
  3868.                            SS
  3869.  
  3870.  
  3871.                        ESP
  3872.  
  3873.                      EFlags
  3874.  
  3875.                            CS
  3876.  
  3877.  
  3878.  
  3879.                        EIP
  3880.  
  3881.  
  3882.                    Error Code
  3883.  
  3884.                          Ret CS
  3885.  
  3886.  
  3887.  
  3888.  
  3889.  
  3890.  
  3891.  
  3892.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 54
  3893.  
  3894.  
  3895.  
  3896.  
  3897.  
  3898.  
  3899.  
  3900.  
  3901.  
  3902.                    Return EIP
  3903.  
  3904.  
  3905.                                  <-- SS:ESP
  3906.  
  3907.                  Shaded fields should not be modified.  Other fields can
  3908.                  be  modified   before  returning   from  the  exception
  3909.                  handler.
  3910.  
  3911.  
  3912.  
  3913.  
  3914.  
  3915.  
  3916.  
  3917.  
  3918.  
  3919.  
  3920.  
  3921.  
  3922.  
  3923.  
  3924.  
  3925.  
  3926.  
  3927.  
  3928.  
  3929.  
  3930.  
  3931.  
  3932.  
  3933.  
  3934.  
  3935.  
  3936.  
  3937.  
  3938.  
  3939.  
  3940.  
  3941.  
  3942.  
  3943.  
  3944.  
  3945.  
  3946.  
  3947.  
  3948.  
  3949.  
  3950.  
  3951.  
  3952.  
  3953.  
  3954.  
  3955.  
  3956.  
  3957.  
  3958.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 55
  3959.  
  3960.  
  3961.  
  3962.  
  3963.  
  3964.  
  3965.  
  3966.  
  3967.  
  3968.              10.5 Get Protected Mode Interrupt Vector
  3969.  
  3970.  
  3971.                  This function  returns  the  CS:(E)IP  of  the  current
  3972.                  protected mode  interrupt  handler  for  the  specified
  3973.                  interrupt number.
  3974.  
  3975.             To Call
  3976.  
  3977.                  AX = 0204h
  3978.                  BL = Interrupt number
  3979.  
  3980.             Returns
  3981.  
  3982.                  Carry flag is clear.
  3983.                  CX:(E)DX = Selector:Offset of exception handler
  3984.  
  3985.             Programmer's Notes
  3986.  
  3987.                  o    The value returned in CX is a valid protected mode
  3988.                       selector, not a real mode segment.
  3989.                  o    32-bit mode  programs will  be returned  a  32-bit
  3990.                       offset in the EDX register.
  3991.                  o    All 100h  (256 decimal)  interrupt vectors must be
  3992.                       supported by the DPMI host.
  3993.  
  3994.  
  3995.  
  3996.  
  3997.  
  3998.  
  3999.  
  4000.  
  4001.  
  4002.  
  4003.  
  4004.  
  4005.  
  4006.  
  4007.  
  4008.  
  4009.  
  4010.  
  4011.  
  4012.  
  4013.  
  4014.  
  4015.  
  4016.  
  4017.  
  4018.  
  4019.  
  4020.  
  4021.  
  4022.  
  4023.  
  4024.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 56
  4025.  
  4026.  
  4027.  
  4028.  
  4029.  
  4030.  
  4031.  
  4032.  
  4033.  
  4034.              10.6 Set Protected Mode Interrupt Vector
  4035.  
  4036.  
  4037.                  This  function   sets  the  address  of  the  specified
  4038.                  protected mode interrupt vector.
  4039.  
  4040.             To Call
  4041.  
  4042.                  AX = 0205h
  4043.                  BL = Interrupt number
  4044.                  CX:(E)DX = Selector:Offset of exception handler
  4045.  
  4046.             Returns
  4047.  
  4048.                  If function was successful:
  4049.                  Carry flag is clear.
  4050.  
  4051.                  If function was not successful:
  4052.                  Carry flag is set.
  4053.  
  4054.             Programmer's Notes
  4055.  
  4056.                  o    The value  passed in  CX must be a valid protected
  4057.                       mode code selector, not a real mode segment.
  4058.                  o    32-bit mode  programs must  supply a 32-bit offset
  4059.                       in the  EDX register.   If  your handler chains to
  4060.                       the next  exception handler  it must do so using a
  4061.                       32-bit interrupt stack frame.
  4062.                  o    Note all 100h (256 decimal) interrupt vectors must
  4063.                       be supported by the DPMI host.
  4064.  
  4065.  
  4066.  
  4067.  
  4068.  
  4069.  
  4070.  
  4071.  
  4072.  
  4073.  
  4074.  
  4075.  
  4076.  
  4077.  
  4078.  
  4079.  
  4080.  
  4081.  
  4082.  
  4083.  
  4084.  
  4085.  
  4086.  
  4087.  
  4088.  
  4089.  
  4090.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 57
  4091.  
  4092.  
  4093.  
  4094.  
  4095.  
  4096.  
  4097.  
  4098.  
  4099.  
  4100.                               11. TRANSLATION SERVICES
  4101.  
  4102.  
  4103.             These services  are provided so that protected mode programs
  4104.             can call  real mode  software that  DPMI  does  not  support
  4105.             directly.   The  protected  mode  program  sets  up  a  data
  4106.             structure that  contains the values for every register.  The
  4107.             data structure is defined as:
  4108.  
  4109.  
  4110.  
  4111.  
  4112.  
  4113.  
  4114.  
  4115.  
  4116.  
  4117.  
  4118.  
  4119.  
  4120.  
  4121.  
  4122.  
  4123.  
  4124.  
  4125.  
  4126.  
  4127.  
  4128.  
  4129.  
  4130.  
  4131.  
  4132.  
  4133.  
  4134.  
  4135.  
  4136.  
  4137.  
  4138.  
  4139.  
  4140.  
  4141.  
  4142.  
  4143.  
  4144.  
  4145.  
  4146.  
  4147.  
  4148.  
  4149.  
  4150.  
  4151.  
  4152.  
  4153.  
  4154.  
  4155.  
  4156.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 58
  4157.  
  4158.  
  4159.  
  4160.  
  4161.  
  4162.  
  4163.  
  4164.  
  4165.  
  4166.                               Offset      Register
  4167.  
  4168.                                 00h         EDI
  4169.  
  4170.                                 04h         ESI
  4171.  
  4172.                                 08h         EBP
  4173.  
  4174.                                 0Ch  Reserved by system
  4175.  
  4176.                                 10h         EBX
  4177.  
  4178.                                 14h         EDX
  4179.  
  4180.                                 18h         ECX
  4181.  
  4182.                                 1Ch         EAX
  4183.  
  4184.  
  4185.                                 20h    Flags
  4186.  
  4187.  
  4188.                                 22h      ES
  4189.  
  4190.  
  4191.                                 24h      DS
  4192.  
  4193.  
  4194.                                 26h      FS
  4195.  
  4196.  
  4197.                                 28h      GS
  4198.  
  4199.  
  4200.                                 2Ah      IP
  4201.  
  4202.  
  4203.                                 2Ch      CS
  4204.  
  4205.  
  4206.                                 2Eh      SP
  4207.  
  4208.  
  4209.                                 30h      SS
  4210.  
  4211.  
  4212.  
  4213.             You will notice that all of the fields are dwords so that 32
  4214.             bit registers  can be  passed to  real mode.  Most real mode
  4215.             software  will   ignore  the   high  word  of  the  extended
  4216.             registers.   However, you  can write  a real  mode procedure
  4217.             that uses  32-bit registers if you desire.  Note that 16-bit
  4218.             DPMI implementations  may not  pass the  high word of 32-bit
  4219.  
  4220.  
  4221.  
  4222.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 59
  4223.  
  4224.  
  4225.  
  4226.  
  4227.  
  4228.  
  4229.  
  4230.  
  4231.             registers or  the FS  and GS  segment registers to real mode
  4232.             even when running on an 80386 machine.
  4233.  
  4234.             Any interrupt  handler or  procedure called must return with
  4235.             the stack  in the  same state  as when  it was called.  This
  4236.             means that  the real mode code may switch stacks while it is
  4237.             running but  it must  return on  the same  stack that it was
  4238.             called on  and it  must pop  off the  entire far return/iret
  4239.             structure.
  4240.  
  4241.             After the  call or  interrupt is  complete,  all  real  mode
  4242.             registers and flags except SS, SP, CS, and IP will be copied
  4243.             back to  the real mode call structure so that the caller can
  4244.             examine the real mode return values.
  4245.  
  4246.             Remember that  the values in the segment registers should be
  4247.             real mode segments, not protected mode selectors.
  4248.  
  4249.             The translation  services will  provide a real mode stack if
  4250.             the SS:SP  fields are  zero.  However, the stack provided is
  4251.             relatively small.   If  the  real  mode  procedure/interrupt
  4252.             routine uses  more than  30 words  of stack  space then  you
  4253.             should provide your own real mode stack.
  4254.  
  4255.             It is  possible to  pass parameters to real mode software on
  4256.             the stack.   The  following  code  will  call  a  real  mode
  4257.             procedure with 3 word parameters:
  4258.  
  4259.  
  4260.                  Protected_Mode_Code:
  4261.                          push    Param1
  4262.                          push    Param2
  4263.                          push    Param3
  4264.                          (Set ES:DI to point to call structure)
  4265.                          mov     cx, 3           ; Copy 3 words
  4266.                          mov     ax, 0301h       ; Call real mode proc
  4267.                          int     31h             ; Call the procedure
  4268.                          add     sp, 6           ; Clean up stack
  4269.  
  4270.             The real  mode procedure  would be called with the following
  4271.             data on the real mode stack:
  4272.  
  4273.  
  4274.  
  4275.  
  4276.  
  4277.  
  4278.  
  4279.  
  4280.  
  4281.  
  4282.  
  4283.  
  4284.  
  4285.  
  4286.  
  4287.  
  4288.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 60
  4289.  
  4290.  
  4291.  
  4292.  
  4293.  
  4294.  
  4295.  
  4296.  
  4297.  
  4298.                                        Param1
  4299.  
  4300.                                        Param2
  4301.  
  4302.                                        Param3
  4303.  
  4304.                                        Return
  4305.                                          CS
  4306.  
  4307.  
  4308.                                        Return
  4309.                                          IP
  4310.  
  4311.                                                  <-- Real mode SS:SP
  4312.  
  4313.  
  4314.  
  4315.  
  4316.  
  4317.  
  4318.  
  4319.  
  4320.  
  4321.  
  4322.  
  4323.  
  4324.  
  4325.  
  4326.  
  4327.  
  4328.  
  4329.  
  4330.  
  4331.  
  4332.  
  4333.  
  4334.  
  4335.  
  4336.  
  4337.  
  4338.  
  4339.  
  4340.  
  4341.  
  4342.  
  4343.  
  4344.  
  4345.  
  4346.  
  4347.  
  4348.  
  4349.  
  4350.  
  4351.  
  4352.  
  4353.  
  4354.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 61
  4355.  
  4356.  
  4357.  
  4358.  
  4359.  
  4360.  
  4361.  
  4362.  
  4363.             If your program needs to perform a series of calls to a real
  4364.             mode  API  it  is  sometimes  more  convenient  to  use  the
  4365.             translation services  to call  a real mode procedure in your
  4366.             own program.  That procedure can then issue the API calls in
  4367.             real mode  and then  return to  protected mode.   This  also
  4368.             avoids the overhead of a mode switch for each API call.
  4369.  
  4370.             There is  also a  mechanism for  protected mode  software to
  4371.             gain control  from real  mode  via  a  real  mode  call-back
  4372.             address.  Real mode call-backs can be used to hook real mode
  4373.             interrupts or  to be called in protected mode by a real mode
  4374.             driver.   For  example,  many  mouse  drivers  will  call  a
  4375.             specified address whenever the mouse is moved.  This service
  4376.             allows the  call-back to  be handled  by software running in
  4377.             protected mode.
  4378.  
  4379.  
  4380.  
  4381.  
  4382.  
  4383.  
  4384.  
  4385.  
  4386.  
  4387.  
  4388.  
  4389.  
  4390.  
  4391.  
  4392.  
  4393.  
  4394.  
  4395.  
  4396.  
  4397.  
  4398.  
  4399.  
  4400.  
  4401.  
  4402.  
  4403.  
  4404.  
  4405.  
  4406.  
  4407.  
  4408.  
  4409.  
  4410.  
  4411.  
  4412.  
  4413.  
  4414.  
  4415.  
  4416.  
  4417.  
  4418.  
  4419.  
  4420.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 62
  4421.  
  4422.  
  4423.  
  4424.  
  4425.  
  4426.  
  4427.  
  4428.  
  4429.  
  4430.              11.1 Simulate Real Mode Interrupt
  4431.  
  4432.  
  4433.                  This function  simulates an interrupt in real mode.  It
  4434.                  will invoke  the  CS:IP  specified  by  the  real  mode
  4435.                  interrupt  vector   and  the  handler  must  return  by
  4436.                  executing an iret.
  4437.  
  4438.             To Call
  4439.  
  4440.                  AX = 0300h
  4441.                  BL = Interrupt number
  4442.                  BH = Flags
  4443.                       Bit 0  = 1 resets the interrupt controller and A20
  4444.                       line
  4445.                       Other flags reserved and must be 0
  4446.                  CX =  Number of  words to  copy from  protected mode to
  4447.                       real mode stack
  4448.                  ES:(E)DI = Selector:Offset of real mode call structure
  4449.  
  4450.             Returns
  4451.  
  4452.                  If function was successful:
  4453.                  Carry flag is clear.
  4454.                  ES:(E)DI =  Selector:Offset of  modified real mode call
  4455.                       structure
  4456.  
  4457.                  If function was not successful:
  4458.                  Carry flag is set.
  4459.  
  4460.             Programmer's Notes
  4461.  
  4462.                  o    The CS:IP  in the  real  mode  call  structure  is
  4463.                       ignored  by   this  service.     The   appropriate
  4464.                       interrupt handler  will be  called  based  on  the
  4465.                       value passed in BL.
  4466.                  o    If the  SS:SP fields  are zero  then a  real  mode
  4467.                       stack  will   be  provided   by  the   DPMI  host.
  4468.                       Otherwise, the  real mode SS:SP will be set to the
  4469.                       specified values  before the  interrupt handler is
  4470.                       called.
  4471.                  o    The  flags   specified  in   the  real  mode  call
  4472.                       structure will  be pushed  on the  real mode stack
  4473.                       iret frame.   The interrupt handler will be called
  4474.                       with the interrupt and trace flags clear.
  4475.                  o    When the  Int 31h  returns,  the  real  mode  call
  4476.                       register structure  will contain  the values  that
  4477.                       were returned by the real mode interrupt handler.
  4478.                  o    It is  up to  the caller  to remove any parameters
  4479.                       that were pushed on the protected mode stack.
  4480.                  o    32-bit programs  must use  ES:EDI to  point to the
  4481.                       real mode  call structure.  16-bit programs should
  4482.                       use ES:DI.
  4483.  
  4484.  
  4485.  
  4486.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 63
  4487.  
  4488.  
  4489.  
  4490.  
  4491.  
  4492.  
  4493.  
  4494.  
  4495.                  o    The flag to reset the interrupt controller and A20
  4496.                       line is  ignored by  DPMI implementations that run
  4497.                       in  Virtual   8086   mode.      It   causes   DPMI
  4498.                       implementations that  return to  real mode  to set
  4499.                       the interrupt  controller  and  A20  address  line
  4500.                       hardware to its normal real mode state.
  4501.  
  4502.  
  4503.  
  4504.  
  4505.  
  4506.  
  4507.  
  4508.  
  4509.  
  4510.  
  4511.  
  4512.  
  4513.  
  4514.  
  4515.  
  4516.  
  4517.  
  4518.  
  4519.  
  4520.  
  4521.  
  4522.  
  4523.  
  4524.  
  4525.  
  4526.  
  4527.  
  4528.  
  4529.  
  4530.  
  4531.  
  4532.  
  4533.  
  4534.  
  4535.  
  4536.  
  4537.  
  4538.  
  4539.  
  4540.  
  4541.  
  4542.  
  4543.  
  4544.  
  4545.  
  4546.  
  4547.  
  4548.  
  4549.  
  4550.  
  4551.  
  4552.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 64
  4553.  
  4554.  
  4555.  
  4556.  
  4557.  
  4558.  
  4559.  
  4560.  
  4561.  
  4562.              11.2 Call Real Mode Procedure With Far Return Frame
  4563.  
  4564.  
  4565.                  This function  calls a real mode procedure.  The called
  4566.                  procedure must execute a far return when it completes.
  4567.  
  4568.             To Call
  4569.  
  4570.                  AX = 0301h
  4571.                  BH = Flags
  4572.                       Bit 0  = 1 resets the interrupt controller and A20
  4573.                       line
  4574.                       Other flags reserved and must be 0
  4575.                  CX =  Number of  words to  copy from  protected mode to
  4576.                       real mode stack
  4577.                  ES:(E)DI = Selector:Offset of real mode call structure
  4578.  
  4579.             Returns
  4580.  
  4581.                  If function was successful:
  4582.                  Carry flag is clear.
  4583.                  ES:(E)DI =  Selector:Offset of  modified real mode call
  4584.                       structure
  4585.  
  4586.                  If function was not successful:
  4587.                  Carry flag is set.
  4588.  
  4589.             Programmer's Notes
  4590.  
  4591.                  o    The  CS:IP   in  the   real  mode  call  structure
  4592.                       specifies the  address of  the real mode procedure
  4593.                       to call.
  4594.                  o    The real  mode procedure must execute a far return
  4595.                       when it has completed.
  4596.                  o    If the  SS:SP fields  are zero  then a  real  mode
  4597.                       stack  will   be  provided   by  the   DPMI  host.
  4598.                       Otherwise, the  real mode SS:SP will be set to the
  4599.                       specified values before the procedure is called.
  4600.                  o    When the  Int 31h  returns,  the  real  mode  call
  4601.                       structure  will   contain  the  values  that  were
  4602.                       returned by the real mode procedure.
  4603.                  o    It is  up to  the caller  to remove any parameters
  4604.                       that were pushed on the protected mode stack.
  4605.                  o    32-bit programs  must use  ES:EDI to  point to the
  4606.                       real mode  call structure.  16-bit programs should
  4607.                       use ES:DI.
  4608.                  o    The flag to reset the interrupt controller and A20
  4609.                       line is  ignored by  DPMI implementations that run
  4610.                       in  Virtual   8086   mode.      It   causes   DPMI
  4611.                       implementations that  return to  real mode  to set
  4612.                       the interrupt  controller  and  A20  address  line
  4613.                       hardware to its normal real mode state.
  4614.  
  4615.  
  4616.  
  4617.  
  4618.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 65
  4619.  
  4620.  
  4621.  
  4622.  
  4623.  
  4624.  
  4625.  
  4626.  
  4627.  
  4628.              11.3 Call Real Mode Procedure With Iret Frame
  4629.  
  4630.  
  4631.                  This function  calls a real mode procedure.  The called
  4632.                  procedure must execute an iret when it completes.
  4633.  
  4634.             To Call
  4635.  
  4636.                  AX = 0302h
  4637.                  BH = Flags
  4638.                       Bit 0  = 1 resets the interrupt controller and A20
  4639.                       line
  4640.                       Other flags reserved and must be 0
  4641.                  CX =  Number of  words to  copy from  protected mode to
  4642.                       real mode stack
  4643.                  ES:(E)DI = Selector:Offset of real mode call structure
  4644.  
  4645.             Returns
  4646.  
  4647.                  If function was successful:
  4648.                  Carry flag is clear.
  4649.                  ES:(E)DI =  Selector:Offset of  modified real mode call
  4650.                       structure
  4651.  
  4652.                  If function was not successful:
  4653.                  Carry flag is set.
  4654.  
  4655.             Programmer's Notes
  4656.  
  4657.                  o    The  CS:IP   in  the   real  mode  call  structure
  4658.                       specifies the  address of  the real mode procedure
  4659.                       to call.
  4660.                  o    The real  mode procedure must execute an iret when
  4661.                       it has completed.
  4662.                  o    If the  SS:SP fields  are zero  then a  real  mode
  4663.                       stack  will   be  provided   by  the   DPMI  host.
  4664.                       Otherwise, the  real mode SS:SP will be set to the
  4665.                       specified values before the procedure is called.
  4666.                  o    When the  Int 31h  returns,  the  real  mode  call
  4667.                       structure  will   contain  the  values  that  were
  4668.                       returned by the real mode procedure.
  4669.                  o    The  flags   specified  in   the  real  mode  call
  4670.                       structure will  be pushed the real mode stack iret
  4671.                       frame.   The procedure  will be  called  with  the
  4672.                       interrupt and trace flags clear.
  4673.                  o    It is  up to  the caller  to remove any parameters
  4674.                       that were pushed on the protected mode stack.
  4675.                  o    32-bit programs  must use  ES:EDI to  point to the
  4676.                       real mode  call structure.  16-bit programs should
  4677.                       use ES:DI.
  4678.                  o    The flag to reset the interrupt controller and A20
  4679.                       line is  ignored by  DPMI implementations that run
  4680.                       in  Virtual   8086   mode.      It   causes   DPMI
  4681.  
  4682.  
  4683.  
  4684.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 66
  4685.  
  4686.  
  4687.  
  4688.  
  4689.  
  4690.  
  4691.  
  4692.  
  4693.                       implementations that  return to  real mode  to set
  4694.                       the interrupt  controller  and  A20  address  line
  4695.                       hardware to its normal real mode state.
  4696.  
  4697.  
  4698.  
  4699.  
  4700.  
  4701.  
  4702.  
  4703.  
  4704.  
  4705.  
  4706.  
  4707.  
  4708.  
  4709.  
  4710.  
  4711.  
  4712.  
  4713.  
  4714.  
  4715.  
  4716.  
  4717.  
  4718.  
  4719.  
  4720.  
  4721.  
  4722.  
  4723.  
  4724.  
  4725.  
  4726.  
  4727.  
  4728.  
  4729.  
  4730.  
  4731.  
  4732.  
  4733.  
  4734.  
  4735.  
  4736.  
  4737.  
  4738.  
  4739.  
  4740.  
  4741.  
  4742.  
  4743.  
  4744.  
  4745.  
  4746.  
  4747.  
  4748.  
  4749.  
  4750.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 67
  4751.  
  4752.  
  4753.  
  4754.  
  4755.  
  4756.  
  4757.  
  4758.  
  4759.  
  4760.              11.4 Allocate Real Mode Call-Back Address
  4761.  
  4762.  
  4763.                  This service  is used  to obtain  a  unique  real  mode
  4764.                  SEG:OFFSET that will transfer control from real mode to
  4765.                  a protected mode procedure.
  4766.  
  4767.                  At times  it is necessary to hook a real mode interrupt
  4768.                  or device  call-back in  a protected  mode driver.  For
  4769.                  example, many  mouse drivers  call an  address whenever
  4770.                  the mouse is moved.  Software running in protected mode
  4771.                  can use  a real  mode call-back  to intercept the mouse
  4772.                  driver calls.
  4773.  
  4774.             To Call
  4775.  
  4776.                  AX = 0303h
  4777.                  DS:(E)SI = Selector:Offset of procedure to call
  4778.                  ES:(E)DI = Selector:Offset of real mode call structure
  4779.  
  4780.             Returns
  4781.  
  4782.                  If function was successful:
  4783.                  Carry flag is clear.
  4784.                  CX:DX = Segment:Offset of real mode call address
  4785.  
  4786.                  If function was not successful:
  4787.                  Carry flag is set.
  4788.  
  4789.             Call-Back Procedure Parameters
  4790.  
  4791.                  Interrupts disabled
  4792.                  DS:(E)SI = Selector:Offset of real mode SS:SP
  4793.                  ES:(E)DI = Selector:Offset of real mode call structure
  4794.                  SS:(E)SP = Locked protected mode API stack
  4795.                  All other registers undefined
  4796.  
  4797.             Return from Call-Back Procedure
  4798.  
  4799.                  Execute an IRET to return
  4800.                  ES:(E)DI =  Selector:Offset of real mode call structure
  4801.                       to restore (see note)
  4802.  
  4803.  
  4804.  
  4805.  
  4806.  
  4807.  
  4808.  
  4809.  
  4810.  
  4811.  
  4812.  
  4813.  
  4814.  
  4815.  
  4816.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 68
  4817.  
  4818.  
  4819.  
  4820.  
  4821.  
  4822.  
  4823.  
  4824.  
  4825.             Programmer's Notes
  4826.  
  4827.                  o    Since the  real mode call structure is static, you
  4828.                       must be  careful when  writing code  that  may  be
  4829.                       reentered.     The  simplest  method  of  avoiding
  4830.                       reentrancy  is   to  leave   interrupts   disabled
  4831.                       throughout the  entire  call.    However,  if  the
  4832.                       amount of  code executed by the call-back is large
  4833.                       then you  will need  to copy  the real  mode  call
  4834.                       structure into  another  buffer.    You  can  then
  4835.                       return with  ES:(E)DI pointing  to the  buffer you
  4836.                       copied the data to -- it does not have to point to
  4837.                       the original real mode call structure.
  4838.                  o    The called  procedure is responsible for modifying
  4839.                       the real mode CS:IP before returning.  If the real
  4840.                       mode CS:IP  is left  unchanged then  the real mode
  4841.                       call-back will  be executed  immediately and  your
  4842.                       procedure will be called again.  Normally you will
  4843.                       want to  pop a return address off of the real mode
  4844.                       stack and  place it  in the  real mode CS:IP.  The
  4845.                       example code  in  the  next  section  demonstrates
  4846.                       chaining  to   another   interrupt   handler   and
  4847.                       simulating a real mode iret.
  4848.                  o    To return  values to the real mode caller you must
  4849.                       modify the real mode call structure.
  4850.                  o    Remember that  all segment values in the real mode
  4851.                       call structure  will contain  real mode  segments,
  4852.                       not selectors.    If  you  need  to  examine  data
  4853.                       pointed to  by a  real mode seg:offset pointer you
  4854.                       should not  use the segment to selector service to
  4855.                       create  a  new  selector.    Instead,  allocate  a
  4856.                       descriptor during  initialization and  change  the
  4857.                       descriptor's  base  to  16  times  the  real  mode
  4858.                       segment's  value.     This   is  important   since
  4859.                       selectors allocated though the segment to selector
  4860.                       service can never be freed.
  4861.                  o    DPMI hosts  should provide  a minimum  of 16 call-
  4862.                       back addresses per task.
  4863.  
  4864.  
  4865.  
  4866.  
  4867.  
  4868.  
  4869.  
  4870.  
  4871.  
  4872.  
  4873.  
  4874.  
  4875.  
  4876.  
  4877.  
  4878.  
  4879.  
  4880.  
  4881.  
  4882.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 69
  4883.  
  4884.  
  4885.  
  4886.  
  4887.  
  4888.  
  4889.  
  4890.  
  4891.             Example Code
  4892.  
  4893.                  The following code is a sample of a real mode interrupt
  4894.                  hook.   It hooks  the DOS  Int 21h and returns an error
  4895.                  for the delete file function (AH=41h).  Other calls are
  4896.                  passed through  to DOS.  This example is somewhat silly
  4897.                  but it  demonstrates the techniques used to hook a real
  4898.                  mode  interrupt.     Note  that  since  DOS  calls  are
  4899.                  reflected  from   protected  mode  to  real  mode,  the
  4900.                  following code  will intercept  all DOS calls from both
  4901.                  real mode and protected mode.
  4902.  
  4903.                  ;******************************************************
  4904.                  ; This procedure gets the current Int 21h real mode
  4905.                  ; Seg:Offset, allocates a real mode call-back address,
  4906.                  ; and sets the real mode Int 21h vector to the call-
  4907.                  ; back address.
  4908.                  ;******************************************************
  4909.                  Initialization_Code:
  4910.                  ;
  4911.                  ; Create a code segment alias to save data in
  4912.                  ;
  4913.                          mov     ax, 000Ah
  4914.                          mov     bx, cs
  4915.                          int     31h
  4916.                          jc      ERROR
  4917.                          mov     ds, ax
  4918.                          ASSUMES DS,_TEXT
  4919.                  ;
  4920.                  ; Get current Int 21h real mode SEG:OFFSET
  4921.                  ;
  4922.                          mov     ax, 0200h
  4923.                          mov     bl, 21h
  4924.                          int     31h
  4925.                          jc      ERROR
  4926.                          mov     [Orig_Real_Seg], cx
  4927.                          mov     [Orig_Real_Offset], dx
  4928.                  ;
  4929.                  ; Allocate a real mode call-back
  4930.                  ;
  4931.                          mov     ax, 0303h
  4932.                          push    ds
  4933.                          mov     bx, cs
  4934.                          mov     ds, bx
  4935.                          mov     si, OFFSET My_Int_21_Hook
  4936.                          pop     es
  4937.                          mov     di, OFFSET My_Real_Mode_Call_Struc
  4938.                          int     31h
  4939.                          jc      ERROR
  4940.                  ;
  4941.                  ; Hook real mode int 21h with the call-back address
  4942.                  ;
  4943.                          mov     ax, 0201h
  4944.                          mov     bl, 21h
  4945.  
  4946.  
  4947.  
  4948.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 70
  4949.  
  4950.  
  4951.  
  4952.  
  4953.  
  4954.  
  4955.  
  4956.  
  4957.                          int     31h
  4958.                          jc      ERROR
  4959.  
  4960.  
  4961.  
  4962.  
  4963.  
  4964.  
  4965.  
  4966.  
  4967.  
  4968.  
  4969.  
  4970.  
  4971.  
  4972.  
  4973.  
  4974.  
  4975.  
  4976.  
  4977.  
  4978.  
  4979.  
  4980.  
  4981.  
  4982.  
  4983.  
  4984.  
  4985.  
  4986.  
  4987.  
  4988.  
  4989.  
  4990.  
  4991.  
  4992.  
  4993.  
  4994.  
  4995.  
  4996.  
  4997.  
  4998.  
  4999.  
  5000.  
  5001.  
  5002.  
  5003.  
  5004.  
  5005.  
  5006.  
  5007.  
  5008.  
  5009.  
  5010.  
  5011.  
  5012.  
  5013.  
  5014.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 71
  5015.  
  5016.  
  5017.  
  5018.  
  5019.  
  5020.  
  5021.  
  5022.  
  5023.                  ;******************************************************
  5024.                  ;
  5025.                  ; This is the actual Int 21h hook code.  It will return
  5026.                  ; an "access denied" error for all calls made in real
  5027.                  ; mode to delete a file.  Other calls will be passed
  5028.                  ; through to DOS.
  5029.                  ;
  5030.                  ; ENTRY:
  5031.                  ;    DS:SI -> Real mode SS:SP
  5032.                  ;    ES:DI -> Real mode call structure
  5033.                  ;    Interrupts disabled
  5034.                  ;
  5035.                  ; EXIT:
  5036.                  ;    ES:DI -> Real mode call structure
  5037.                  ;
  5038.                  ;******************************************************
  5039.  
  5040.                  My_Int_21_Hook:
  5041.                          cmp     es:[di.RealMode_AH], 41h
  5042.                          jne     Chain_To_DOS
  5043.                  ;
  5044.                  ; This is a delete file call (AH=41h).  Simulate an
  5045.                  ; iret on the real mode stack, set the real mode
  5046.                  ; carry flag, and set the real mode AX to 5 to indicate
  5047.                  ; an access denied error.
  5048.                  ;
  5049.                          cld
  5050.                          lodsw                   ; Get real mode ret IP
  5051.                          mov     es:[di.RealMode_IP], ax
  5052.                          lodsw                   ; Get real mode ret CS
  5053.                          mov     es:[di.RealMode_CS], ax
  5054.                          lodsw                   ; Get real mode flags
  5055.                          or      ax, 1           ; Set carry flag
  5056.                          mov     es:[di.RealMode_Flags], ax
  5057.                          add     es:[di.RealMode_SP], 6
  5058.                          mov     es:[di.RealMode_AX], 5
  5059.                          jmp     My_Hook_Exit
  5060.                  ;
  5061.                  ; Chain to original Int 21h vector by replacing the
  5062.                  ; real mode CS:IP with the original Seg:Offset.
  5063.                  ;
  5064.                  Chain_To_DOS:
  5065.                          mov     ax, cs:[Orig_Real_Seg]
  5066.                          mov     es:[di.RealMode_CS], ax
  5067.                          mov     ax, cs:[Orig_Real_Offset]
  5068.                          mov     es:[di.RealMode_IP], ax
  5069.  
  5070.                  My_Hook_Exit:
  5071.                          iret
  5072.  
  5073.  
  5074.  
  5075.  
  5076.  
  5077.  
  5078.  
  5079.  
  5080.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 72
  5081.  
  5082.  
  5083.  
  5084.  
  5085.  
  5086.  
  5087.  
  5088.  
  5089.  
  5090.              11.5 Free Real Mode Call-Back Address
  5091.  
  5092.  
  5093.  
  5094.                  This function  frees a real mode call-back address that
  5095.                  was allocated  through the allocate real mode call-back
  5096.                  address service.
  5097.  
  5098.             To Call
  5099.  
  5100.                  AX = 0304h
  5101.                  CX:DX = Real mode call-back address to free
  5102.  
  5103.             Returns
  5104.  
  5105.                  If function was successful:
  5106.                  Carry flag is clear.
  5107.  
  5108.                  If function was not successful:
  5109.                  Carry flag is set.
  5110.  
  5111.             Programmer's Notes
  5112.  
  5113.                  o    Real mode call-backs are a limited resource.  Your
  5114.                       code should  free any  break point  that it  is no
  5115.                       longer using.
  5116.  
  5117.  
  5118.  
  5119.  
  5120.  
  5121.  
  5122.  
  5123.  
  5124.  
  5125.  
  5126.  
  5127.  
  5128.  
  5129.  
  5130.  
  5131.  
  5132.  
  5133.  
  5134.  
  5135.  
  5136.  
  5137.  
  5138.  
  5139.  
  5140.  
  5141.  
  5142.  
  5143.  
  5144.  
  5145.  
  5146.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 73
  5147.  
  5148.  
  5149.  
  5150.  
  5151.  
  5152.  
  5153.  
  5154.  
  5155.  
  5156.              11.6 Get State Save/Restore Addresses
  5157.  
  5158.  
  5159.                  When a  program uses  the raw mode switch services (see
  5160.                  page 77)  or issues DOS calls from a hardware interrupt
  5161.                  handler, it  will need to save the state of the current
  5162.                  task before  changing modes.   This service returns the
  5163.                  addresses of  two procedures  used to save the state of
  5164.                  the current  task's registers.   For  example, the real
  5165.                  mode address is used to save the state of the protected
  5166.                  mode registers.   The protected mode address is used to
  5167.                  save the state of the real mode registers.  This can be
  5168.                  used  to   save  the  state  of  the  alternate  mode's
  5169.                  registers before  they are  modified by the mode switch
  5170.                  call.   The current  mode's registers  can be  saved by
  5171.                  simply pushing them on the stack.
  5172.  
  5173.                  Note:   It is  not necessary  to call  this service  if
  5174.                  using the  translation services  0300h, 0301h or 0302h.
  5175.                  It is  provided for  programs that  use  the  raw  mode
  5176.                  switch service.
  5177.  
  5178.             To Call
  5179.  
  5180.                  AX = 0305h
  5181.  
  5182.             Returns
  5183.  
  5184.                  If function was successful:
  5185.                  Carry flag is clear
  5186.                  AX = Size of buffer in bytes required to save state
  5187.                  BX:CX = Real mode address used to save/restore state
  5188.                  SI:(E)DI =  Protected mode address used to save/restore
  5189.                       state
  5190.  
  5191.                  If function was not successful:
  5192.                  Carry flag is set
  5193.  
  5194.             Parameters To State-Save Procedures
  5195.  
  5196.                  Execute a  far call to the appropriate address (real or
  5197.                       pmode) with:
  5198.                  ES:(E)DI = Pointer to state-save buffer
  5199.                  AL = 0 to save state
  5200.                  AL = 1 to restore state
  5201.  
  5202.             Programmer's Notes
  5203.  
  5204.                  o    Some implementations  of DPMI will not require the
  5205.                       state to  be saved.  In this case, the buffer size
  5206.                       returned will be zero.  However, it is still valid
  5207.                       to call the addresses returned, although they will
  5208.  
  5209.  
  5210.  
  5211.  
  5212.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 74
  5213.  
  5214.  
  5215.  
  5216.  
  5217.  
  5218.  
  5219.  
  5220.  
  5221.                       just  return   without   performing   any   useful
  5222.                       function.
  5223.                  o    The save/restore  functions will  not  modify  any
  5224.                       registers.
  5225.                  o    The address  returned in BX:CX must only be called
  5226.                       in real  mode.   The address  returned in SI:(E)DI
  5227.                       must only be called in protected mode.
  5228.                  o    16-bit programs  should call  the address returned
  5229.                       in SI:DI  to save  the real  mode state.    32-bit
  5230.                       programs  should  call  the  address  returned  in
  5231.                       SI:EDI.
  5232.  
  5233.  
  5234.  
  5235.  
  5236.  
  5237.  
  5238.  
  5239.  
  5240.  
  5241.  
  5242.  
  5243.  
  5244.  
  5245.  
  5246.  
  5247.  
  5248.  
  5249.  
  5250.  
  5251.  
  5252.  
  5253.  
  5254.  
  5255.  
  5256.  
  5257.  
  5258.  
  5259.  
  5260.  
  5261.  
  5262.  
  5263.  
  5264.  
  5265.  
  5266.  
  5267.  
  5268.  
  5269.  
  5270.  
  5271.  
  5272.  
  5273.  
  5274.  
  5275.  
  5276.  
  5277.  
  5278.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 75
  5279.  
  5280.  
  5281.  
  5282.  
  5283.  
  5284.  
  5285.  
  5286.  
  5287.             Example Code
  5288.  
  5289.                  The following  code is  a sample  protected mode  timer
  5290.                  interrupt handler that saves the state of the real mode
  5291.                  registers, issues  DOS calls,  and restores  the state.
  5292.                  This code  assumes that  the Int 31h function 0305h has
  5293.                  been executed and that the call address and buffer size
  5294.                  have been saved in local variables.
  5295.  
  5296.                  Sample_Timer_Code:
  5297.                          pushf
  5298.                          call    FAR PTR cs:[Next_Timer_Handler]
  5299.                          sti
  5300.                  ;
  5301.                  ; Save protected mode registers
  5302.                  ;
  5303.                          push    ds
  5304.                          push    es
  5305.                          pusha
  5306.                  ;
  5307.                  ; Save real mode registers
  5308.                  ;
  5309.                          mov     ds, cs:[My_Local_DS]
  5310.                          mov     ax, ss
  5311.                          mov     es, ax
  5312.                          sub     sp, [State_Save_Size]
  5313.                          mov     di, sp
  5314.                          xor     al, al
  5315.                          call    [PM_Save_Restore_State]
  5316.  
  5317.                  ;
  5318.                  ; Raw mode switch here
  5319.                  ;
  5320.                          .
  5321.                          .
  5322.                          .
  5323.                  ;
  5324.                  ; Restore real mode registers
  5325.                  ;
  5326.                          mov     ax, ss
  5327.                          mov     es, ax
  5328.                          mov     di, sp
  5329.                          mov     al, 1
  5330.                          call    [PM_Save_Restore_State]
  5331.                          add     sp, [State_Save_Size]
  5332.                  ;
  5333.                  ; Restore protected mode registers and return
  5334.                  ;
  5335.                          popa
  5336.                          pop     es
  5337.                          pop     ds
  5338.  
  5339.                          iret
  5340.  
  5341.  
  5342.  
  5343.  
  5344.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 76
  5345.  
  5346.  
  5347.  
  5348.  
  5349.  
  5350.  
  5351.  
  5352.  
  5353.  
  5354.              11.7 Get Raw Mode Switch Addresses
  5355.  
  5356.  
  5357.  
  5358.  
  5359.                  This function returns addresses that can be jumped to
  5360.             for low-level mode switching.To Call
  5361.  
  5362.                  AX = 0306h
  5363.  
  5364.             Returns
  5365.  
  5366.                  If function was successful:
  5367.                  Carry flag is clear
  5368.                  BX:CX = Real -> Protected mode switch address
  5369.                  SI:(E)DI = Protected -> Real mode switch address
  5370.  
  5371.                  If function was not successful:
  5372.                  Carry flag is set
  5373.  
  5374.             Parameters To State-Save Procedures
  5375.  
  5376.                  Execute a  far jump to the appropriate address (real or
  5377.                       pmode) with:
  5378.                  AX   = New DS
  5379.                  CX   = New ES
  5380.                  DX   = New SS
  5381.                  (E)BX     = New (E)SP
  5382.                  SI   = New CS
  5383.                  (E)DI     = New (E)IP
  5384.  
  5385.                  The processor  will be placed in the desired mode.  The
  5386.                  DS, ES,  SS, (E)SP,  CS, and  (E)IP  will  contain  the
  5387.                  values specified.  The (E)BP register will be preserved
  5388.                  across the  call and  so can be used as a pointer.  The
  5389.                  values in  (E)AX, (E)BX, (E)CX, (E)DX, (E)SI, and (E)DI
  5390.                  will be  undefined.  On an 80386 or 80486 the FS and GS
  5391.                  segment registers  will contain  zero  after  the  mode
  5392.                  switch.
  5393.  
  5394.             Programmer's Notes
  5395.  
  5396.                  o    The address  returned in BX:CX must only be called
  5397.                       in real  mode to  switch into protected mode.  The
  5398.                       address returned  in SI:(E)DI  must only be called
  5399.                       in protected mode to switch into real mode.
  5400.                  o    16-bit programs  should call  the address returned
  5401.                       in SI:DI  to switch  from protected  to real mode.
  5402.                       32-bit programs  should call  the address returned
  5403.                       in SI:EDI.
  5404.                  o    It is  up to  the caller  to save  and restore the
  5405.                       state of  the task  when using  this  function  to
  5406.  
  5407.  
  5408.  
  5409.  
  5410.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 77
  5411.  
  5412.  
  5413.  
  5414.  
  5415.  
  5416.  
  5417.  
  5418.  
  5419.                       switch modes.   This  usually requires  using  the
  5420.                       state save function (see page 74).
  5421.                  o    The  parameters   must  contain   segment   values
  5422.                       appropriate for  the mode  that is  being switched
  5423.                       to.   If  invalid  selectors  are  specified  when
  5424.                       switching into  protected mode,  an exception will
  5425.                       occur.
  5426.                  o    Applications  may  find  functions  0300h,  0301h,
  5427.                       0302h, and 0304h more convenient to use than using
  5428.                       this type of mode switching.
  5429.  
  5430.  
  5431.  
  5432.  
  5433.  
  5434.  
  5435.  
  5436.  
  5437.  
  5438.  
  5439.  
  5440.  
  5441.  
  5442.  
  5443.  
  5444.  
  5445.  
  5446.  
  5447.  
  5448.  
  5449.  
  5450.  
  5451.  
  5452.  
  5453.  
  5454.  
  5455.  
  5456.  
  5457.  
  5458.  
  5459.  
  5460.  
  5461.  
  5462.  
  5463.  
  5464.  
  5465.  
  5466.  
  5467.  
  5468.  
  5469.  
  5470.  
  5471.  
  5472.  
  5473.  
  5474.  
  5475.  
  5476.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 78
  5477.  
  5478.  
  5479.  
  5480.  
  5481.  
  5482.  
  5483.  
  5484.  
  5485.  
  5486.                                   12. GET VERSION
  5487.  
  5488.  
  5489.             Function  0400h   returns  the   version  of  DPMI  services
  5490.             supported.  Note that this is not necessarily the version of
  5491.             any operating  system that supports DPMI.  It should be used
  5492.             by programs to determine what calls are legal in the current
  5493.             environment.
  5494.  
  5495.             To Call
  5496.  
  5497.                  AX = 0400h
  5498.  
  5499.             Returns
  5500.  
  5501.                  AH = Major version
  5502.                  AL = Minor version
  5503.                  BX = Flags
  5504.                       Bit  0   =  1  if  running  under  an  80386  DPMI
  5505.                       implementation
  5506.                       Bit 1  = 1  if  processor is returned to real mode
  5507.                       for reflected  interrupts (as  opposed to  Virtual
  5508.                       8086 mode).
  5509.                       Bit 2 = 1 if virtual memory is supported
  5510.                       Bit 3 is reserved and undefined
  5511.                       All other bits are zero and reserved for later use
  5512.                  CL = Processor type
  5513.                       02 = 80286
  5514.                       03 = 80386
  5515.                       04 = 80486
  5516.                  DH = Current value of virtual master PIC base interrupt
  5517.                  DL = Current value of virtual slave PIC base interrupt
  5518.                  Carry flag clear (call can not fail)
  5519.  
  5520.             Programmer's Notes
  5521.  
  5522.                  None
  5523.  
  5524.  
  5525.  
  5526.  
  5527.  
  5528.  
  5529.  
  5530.  
  5531.  
  5532.  
  5533.  
  5534.  
  5535.  
  5536.  
  5537.  
  5538.  
  5539.  
  5540.  
  5541.  
  5542.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 79
  5543.  
  5544.  
  5545.  
  5546.  
  5547.  
  5548.  
  5549.  
  5550.  
  5551.  
  5552.                            13. MEMORY MANAGEMENT SERVICES
  5553.  
  5554.  
  5555.             These functions  are provided  to  allocate  linear  address
  5556.             space.
  5557.  
  5558.  
  5559.  
  5560.  
  5561.  
  5562.  
  5563.  
  5564.  
  5565.  
  5566.  
  5567.  
  5568.  
  5569.  
  5570.  
  5571.  
  5572.  
  5573.  
  5574.  
  5575.  
  5576.  
  5577.  
  5578.  
  5579.  
  5580.  
  5581.  
  5582.  
  5583.  
  5584.  
  5585.  
  5586.  
  5587.  
  5588.  
  5589.  
  5590.  
  5591.  
  5592.  
  5593.  
  5594.  
  5595.  
  5596.  
  5597.  
  5598.  
  5599.  
  5600.  
  5601.  
  5602.  
  5603.  
  5604.  
  5605.  
  5606.  
  5607.  
  5608.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 80
  5609.  
  5610.  
  5611.  
  5612.  
  5613.  
  5614.  
  5615.  
  5616.  
  5617.  
  5618.              13.1 Get Free Memory Information
  5619.  
  5620.  
  5621.                  This  function  is  provided  so  that  protected  mode
  5622.                  applications  can   determine  how   much   memory   is
  5623.                  available.   Under DPMI  implementations  that  support
  5624.                  virtual memory, it is important to consider issues such
  5625.                  as the amount of available physical memory.
  5626.  
  5627.                  Note that  since DPMI  applications will  often run  in
  5628.                  multi-tasking  environments,   this  function  must  be
  5629.                  considered only advisory.
  5630.  
  5631.             To Call
  5632.  
  5633.                  AX = 0500h
  5634.                  ES:(E)DI = Selector:Offset of 30h byte buffer
  5635.  
  5636.             Returns
  5637.  
  5638.                  If function was successful:
  5639.                  Carry flag is clear.
  5640.                  ES:(E)DI = Selector:Offset of buffer with the following
  5641.                       structure:
  5642.  
  5643.  
  5644.  
  5645.  
  5646.  
  5647.  
  5648.  
  5649.  
  5650.  
  5651.  
  5652.  
  5653.  
  5654.  
  5655.  
  5656.  
  5657.  
  5658.  
  5659.  
  5660.  
  5661.  
  5662.  
  5663.  
  5664.  
  5665.  
  5666.  
  5667.  
  5668.  
  5669.  
  5670.  
  5671.  
  5672.  
  5673.  
  5674.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 81
  5675.  
  5676.  
  5677.  
  5678.  
  5679.  
  5680.  
  5681.  
  5682.  
  5683.  
  5684.                        Offset           Description
  5685.  
  5686.                         00h   Largest available free block in
  5687.                        bytes
  5688.  
  5689.                         04h   Maximum unlocked page allocation
  5690.  
  5691.                         08h    Maximum locked page allocation
  5692.  
  5693.                         0Ch   Linear addr space size in pages
  5694.  
  5695.                         10h    Total number of unlocked pages
  5696.  
  5697.                         14h         Number of free pages
  5698.  
  5699.                         18h    Total number of physical pages
  5700.  
  5701.                         1Ch  Free linear address space in pages
  5702.  
  5703.                         20h   Size of paging file/partition in
  5704.                        pages
  5705.  
  5706.  
  5707.  
  5708.  
  5709.                        24h-2Fh            Reserved
  5710.  
  5711.  
  5712.  
  5713.  
  5714.  
  5715.                  If function was not successful:
  5716.                  Carry flag is set.
  5717.  
  5718.  
  5719.  
  5720.  
  5721.  
  5722.  
  5723.  
  5724.  
  5725.  
  5726.  
  5727.  
  5728.  
  5729.  
  5730.  
  5731.  
  5732.  
  5733.  
  5734.  
  5735.  
  5736.  
  5737.  
  5738.  
  5739.  
  5740.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 82
  5741.  
  5742.  
  5743.  
  5744.  
  5745.  
  5746.  
  5747.  
  5748.  
  5749.             Programmer's Notes
  5750.  
  5751.                  o    32-bit programs  must use  ES:EDI to  point to the
  5752.                       buffer.  16-bit programs should use ES:DI.
  5753.                  o    DPMI implementations  that do  not support virtual
  5754.                       memory (returned  in flags  from Get Version call)
  5755.                       will only  fill in  the first  field.   This value
  5756.                       specifies that  largest allocation  that could  be
  5757.                       made using  function 0501h.   Other fields will be
  5758.                       set to -1.
  5759.                  o    Only  the   first  field   of  this  structure  is
  5760.                       guaranteed to  contain a  valid value.  All fields
  5761.                       that are  not returned  by the DPMI implementation
  5762.                       will be  set to  -1 (0FFFFFFFFh)  to indicate that
  5763.                       the information is not available.
  5764.                  o    The field  at offset  00h  specifies  the  largest
  5765.                       block of  contiguous linear  memory in  bytes that
  5766.                       could be  allocated  if  the  memory  were  to  be
  5767.                       allocated and left unlocked.
  5768.                  o    The field  at offset  04h specifies  the number of
  5769.                       pages that  could be allocated.  This is the value
  5770.                       returned by field 00h / page size.
  5771.                  o    The field  at offset  08h  specifies  the  largest
  5772.                       block of  memory in  pages that could be allocated
  5773.                       and then locked.
  5774.                  o    The field  at offset 0Ch specifies the size of the
  5775.                       total  linear   address  space  in  pages.    This
  5776.                       includes all linear address space that has already
  5777.                       been allocated.
  5778.                  o    The field at offset 10h specifies the total number
  5779.                       of pages  that are currently unlocked and could be
  5780.                       paged out.   This  value also  contains  any  free
  5781.                       pages.
  5782.                  o    The field  at offset  14h specifies  the number of
  5783.                       physical pages that currently are not in use.
  5784.                  o    The field at offset 18h specifies the total number
  5785.                       of physical  pages that  the  DPMI  host  manages.
  5786.                       This value includes all free, locked, and unlocked
  5787.                       physical pages.
  5788.                  o    The field  at offset 20h specifies the size of the
  5789.                       DPMI host's paging partition or file in pages.
  5790.                  o    To determine  the size  of pages for the DPMI host
  5791.                       call the Get Page Size service (see page 93).
  5792.  
  5793.  
  5794.  
  5795.  
  5796.  
  5797.  
  5798.  
  5799.  
  5800.  
  5801.  
  5802.  
  5803.  
  5804.  
  5805.  
  5806.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 83
  5807.  
  5808.  
  5809.  
  5810.  
  5811.  
  5812.  
  5813.  
  5814.  
  5815.  
  5816.              13.2 Allocate Memory Block
  5817.  
  5818.  
  5819.                  This function allocates and commits linear memory.
  5820.  
  5821.             To Call
  5822.  
  5823.                  AX = 0501h
  5824.                  BX:CX = Size of memory block to allocate in bytes
  5825.  
  5826.             Returns
  5827.  
  5828.                  If function was successful:
  5829.                  Carry flag is clear
  5830.                  BX:CX = Linear address of allocated memory block
  5831.                  SI:DI = Memory block handle (used to resize and free)
  5832.  
  5833.                  If function was unsuccessful:
  5834.                  Carry flag is set
  5835.  
  5836.             Programmer's Notes
  5837.  
  5838.                  o    This function  does not allocate any selectors for
  5839.                       the memory block.  It is the responsibility of the
  5840.                       caller to  allocate and  initialize any  selectors
  5841.                       needed to access the memory.
  5842.                  o    Under DPMI  implementations that  support  virtual
  5843.                       memory  the   memory  block   will  be   allocated
  5844.                       unlocked.   If some or all of the memory should be
  5845.                       locked you  will  need  to  use  either  the  lock
  5846.                       selector  function   or  the  lock  linear  region
  5847.                       function.
  5848.                  o    Under many  implementations of  DPMI,  allocations
  5849.                       will  be  page  granular.    This  means  that  an
  5850.                       allocation  of  1001h  bytes  will  result  in  an
  5851.                       allocation of  2000h bytes.   Therefore it is best
  5852.                       to always allocate memory in multiples of 4K.
  5853.  
  5854.  
  5855.  
  5856.  
  5857.  
  5858.  
  5859.  
  5860.  
  5861.  
  5862.  
  5863.  
  5864.  
  5865.  
  5866.  
  5867.  
  5868.  
  5869.  
  5870.  
  5871.  
  5872.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 84
  5873.  
  5874.  
  5875.  
  5876.  
  5877.  
  5878.  
  5879.  
  5880.  
  5881.  
  5882.              13.3 Free Memory Block
  5883.  
  5884.  
  5885.                  This function  frees a  memory block  that was allocate
  5886.                  through the allocate memory block function.
  5887.  
  5888.             To Call
  5889.  
  5890.                  AX = 0502h
  5891.                  SI:DI = Handle of memory block to free
  5892.  
  5893.             Returns
  5894.  
  5895.                  If function was successful:
  5896.                  Carry flag is clear
  5897.  
  5898.                  If function was unsuccessful:
  5899.                  Carry flag is set
  5900.  
  5901.             Programmer's Notes
  5902.  
  5903.                  o    Your program  must also free any selectors that it
  5904.                       allocated to point to the memory block.
  5905.  
  5906.  
  5907.  
  5908.  
  5909.  
  5910.  
  5911.  
  5912.  
  5913.  
  5914.  
  5915.  
  5916.  
  5917.  
  5918.  
  5919.  
  5920.  
  5921.  
  5922.  
  5923.  
  5924.  
  5925.  
  5926.  
  5927.  
  5928.  
  5929.  
  5930.  
  5931.  
  5932.  
  5933.  
  5934.  
  5935.  
  5936.  
  5937.  
  5938.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 85
  5939.  
  5940.  
  5941.  
  5942.  
  5943.  
  5944.  
  5945.  
  5946.  
  5947.  
  5948.              13.4 Resize Memory Block
  5949.  
  5950.  
  5951.                  This function  changes the  size of a memory block that
  5952.                  was  allocated   through  the   allocate  memory  block
  5953.                  function.
  5954.  
  5955.             To Call
  5956.  
  5957.                  AX = 0503h
  5958.                  BX:CX = New size of memory block to allocate in bytes
  5959.                  SI:DI = Handle of memory block to resize
  5960.  
  5961.             Returns
  5962.  
  5963.                  If function was successful:
  5964.                  Carry flag is clear
  5965.                  BX:CX = New linear address of memory block
  5966.                  SI:DI = New handle of memory block
  5967.  
  5968.                  If function was unsuccessful:
  5969.                  Carry flag is set
  5970.  
  5971.             Programmer's Notes
  5972.  
  5973.                  o    This function may change the linear address of the
  5974.                       memory block  and the  memory handle.   Therefore,
  5975.                       you will  need to  update any selectors that point
  5976.                       to the  block after resizing it.  You must use the
  5977.                       new handle instead of the old one.
  5978.                  o    This function  will generate  an error if a memory
  5979.                       block is resized to 0 bytes.
  5980.  
  5981.  
  5982.  
  5983.  
  5984.  
  5985.  
  5986.  
  5987.  
  5988.  
  5989.  
  5990.  
  5991.  
  5992.  
  5993.  
  5994.  
  5995.  
  5996.  
  5997.  
  5998.  
  5999.  
  6000.  
  6001.  
  6002.  
  6003.  
  6004.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 86
  6005.  
  6006.  
  6007.  
  6008.  
  6009.  
  6010.  
  6011.  
  6012.  
  6013.  
  6014.                              14. PAGE LOCKING SERVICES
  6015.  
  6016.  
  6017.             These services  are only  useful under  DPMI implementations
  6018.             that support virtual memory.  They will be ignored by 16-bit
  6019.             DPMI implementations  (although they will always return with
  6020.             carry clear to indicate success).
  6021.  
  6022.             Some  implementations   of  DPMI  may  ignore  these  calls.
  6023.             However, if the calls are ignored then the DPMI host will be
  6024.             able to  handle page  faults at  arbitrary points during the
  6025.             application's execution  including interrupt  and  exception
  6026.             handler code.
  6027.  
  6028.             Although memory  ranges are  specified in  bytes, the actual
  6029.             unit of  memory that  will be  locked will  be one  or  more
  6030.             pages.   Page locks  are maintained  as a  count.   When the
  6031.             count is  decremented to  zero, the page is unlocked and can
  6032.             be swapped  to disk.   This means that if a region of memory
  6033.             is locked  three times  then it must be unlocked three times
  6034.             before the pages will be unlocked.
  6035.  
  6036.  
  6037.  
  6038.  
  6039.  
  6040.  
  6041.  
  6042.  
  6043.  
  6044.  
  6045.  
  6046.  
  6047.  
  6048.  
  6049.  
  6050.  
  6051.  
  6052.  
  6053.  
  6054.  
  6055.  
  6056.  
  6057.  
  6058.  
  6059.  
  6060.  
  6061.  
  6062.  
  6063.  
  6064.  
  6065.  
  6066.  
  6067.  
  6068.  
  6069.  
  6070.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 87
  6071.  
  6072.  
  6073.  
  6074.  
  6075.  
  6076.  
  6077.  
  6078.  
  6079.  
  6080.              14.1 Lock Linear Region
  6081.  
  6082.  
  6083.                  This function locks a specified linear address range.
  6084.  
  6085.             To Call
  6086.  
  6087.                  AX = 0600h
  6088.                  BX:CX = Starting linear address of memory to lock
  6089.                  SI:DI = Size of region to lock in bytes
  6090.  
  6091.             Returns
  6092.  
  6093.                  If function was successful:
  6094.                  Carry flag is clear.
  6095.  
  6096.                  If function was not successful:
  6097.                  Carry flag is set.
  6098.  
  6099.             Programmer's Notes
  6100.  
  6101.                  o    If this  function fails  then none  of the  memory
  6102.                       will be locked.
  6103.                  o    If the specified region overlaps part of a page at
  6104.                       the beginning  or end  of the  region, the page(s)
  6105.                       will be locked.
  6106.  
  6107.  
  6108.  
  6109.  
  6110.  
  6111.  
  6112.  
  6113.  
  6114.  
  6115.  
  6116.  
  6117.  
  6118.  
  6119.  
  6120.  
  6121.  
  6122.  
  6123.  
  6124.  
  6125.  
  6126.  
  6127.  
  6128.  
  6129.  
  6130.  
  6131.  
  6132.  
  6133.  
  6134.  
  6135.  
  6136.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 88
  6137.  
  6138.  
  6139.  
  6140.  
  6141.  
  6142.  
  6143.  
  6144.  
  6145.  
  6146.              14.2 Unlock Linear Region
  6147.  
  6148.  
  6149.                  This function  unlocks a specified linear address range
  6150.                  that was previously locked using the Lock Linear Region
  6151.                  function.
  6152.  
  6153.             To Call
  6154.  
  6155.                  AX = 0601h
  6156.                  BX:CX = Starting linear address of memory to unlock
  6157.                  SI:DI = Size of region to unlock in bytes
  6158.  
  6159.             Returns
  6160.  
  6161.                  If function was successful:
  6162.                  Carry flag is clear.
  6163.  
  6164.                  If function was not successful:
  6165.                  Carry flag is set.
  6166.  
  6167.             Programmer's Notes
  6168.  
  6169.                  o    If this  function fails  then none  of the  memory
  6170.                       will be unlocked.
  6171.                  o    An error  will be  returned if  the memory was not
  6172.                       previously locked  or if  the specified  region is
  6173.                       invalid.
  6174.                  o    If the specified region overlaps part of a page at
  6175.                       the beginning  or end  of the  region, the page(s)
  6176.                       will be unlocked.
  6177.                  o    Even if  the function  succeeds, the  memory  will
  6178.                       remain locked if the lock count is not decremented
  6179.                       to zero.
  6180.  
  6181.  
  6182.  
  6183.  
  6184.  
  6185.  
  6186.  
  6187.  
  6188.  
  6189.  
  6190.  
  6191.  
  6192.  
  6193.  
  6194.  
  6195.  
  6196.  
  6197.  
  6198.  
  6199.  
  6200.  
  6201.  
  6202.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 89
  6203.  
  6204.  
  6205.  
  6206.  
  6207.  
  6208.  
  6209.  
  6210.  
  6211.  
  6212.              14.3 Mark Real Mode Region as Pageable
  6213.  
  6214.  
  6215.                  Under some  implementations  of  DPMI,  all  memory  in
  6216.                  virtual 8086 mode is locked by default.  If a protected
  6217.                  mode program  is using  memory in the first megabyte of
  6218.                  address space,  it is  a good idea to use this function
  6219.                  to turn  off automatic  page  locking  for  regions  of
  6220.                  memory that will not be touched at interrupt time.
  6221.  
  6222.                  Do not  mark memory as pageable in regions that are not
  6223.                  owned by your application.  For example, you should not
  6224.                  mark all free DOS memory as pageable since it may cause
  6225.                  a page  fault to  occur while  inside of DOS (causing a
  6226.                  crash).   Also, do  not mark the DPMI host data area as
  6227.                  pageable.
  6228.  
  6229.                  It is  very important  to relock  any real  mode memory
  6230.                  using function  0603h  before  terminating  a  program.
  6231.                  Memory  that  remains  unlocked  after  a  program  has
  6232.                  terminated could result in fatal page faults when other
  6233.                  software is executed in that address space.
  6234.  
  6235.                  Note that  address space  marked as  pageable  by  this
  6236.                  function can  be locked  using function  0600h.    This
  6237.                  function is  just an  advisory service  to allow memory
  6238.                  that does  not need to be locked to be paged out.  This
  6239.                  function just  disables any  automatic locking  of real
  6240.                  mode memory performed by the DPMI host.
  6241.  
  6242.             To Call
  6243.  
  6244.                  AX = 0602h
  6245.                  BX:CX =  Starting linear  address of  memory to mark as
  6246.                       pageable
  6247.                  SI:DI = Size of region to page in bytes
  6248.  
  6249.             Returns
  6250.  
  6251.                  If function was successful:
  6252.                  Carry flag is clear.
  6253.  
  6254.                  If function was not successful:
  6255.                  Carry flag is set.
  6256.  
  6257.             Programmer's Notes
  6258.  
  6259.                  o    If this  function fails  then none  of the  memory
  6260.                       will be unlocked.
  6261.                  o    If the specified region overlaps part of a page at
  6262.                       the beginning  or end  of the  region, the page(s)
  6263.                       will be not be marked as pageable.
  6264.  
  6265.  
  6266.  
  6267.  
  6268.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 90
  6269.  
  6270.  
  6271.  
  6272.  
  6273.  
  6274.  
  6275.  
  6276.  
  6277.                  o    When  your   program  terminates  it  should  call
  6278.                       function 0603h to relock the memory region.
  6279.                  o    Unlike the  lock and unlock calls, the pageability
  6280.                       of the  real mode region is maintained as a binary
  6281.                       state, not  a count.   Therefore, do not call this
  6282.                       function multiple times for a given linear region.
  6283.  
  6284.  
  6285.  
  6286.  
  6287.  
  6288.  
  6289.  
  6290.  
  6291.  
  6292.  
  6293.  
  6294.  
  6295.  
  6296.  
  6297.  
  6298.  
  6299.  
  6300.  
  6301.  
  6302.  
  6303.  
  6304.  
  6305.  
  6306.  
  6307.  
  6308.  
  6309.  
  6310.  
  6311.  
  6312.  
  6313.  
  6314.  
  6315.  
  6316.  
  6317.  
  6318.  
  6319.  
  6320.  
  6321.  
  6322.  
  6323.  
  6324.  
  6325.  
  6326.  
  6327.  
  6328.  
  6329.  
  6330.  
  6331.  
  6332.  
  6333.  
  6334.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 91
  6335.  
  6336.  
  6337.  
  6338.  
  6339.  
  6340.  
  6341.  
  6342.  
  6343.  
  6344.              14.4 Relock Real Mode Region
  6345.  
  6346.  
  6347.                  This function  is used  to relock  memory regions  that
  6348.                  were marked as pageable by the previous function.
  6349.  
  6350.             To Call
  6351.  
  6352.                  AX = 0603h
  6353.                  BX:CX = Starting linear address of memory to relock
  6354.                  SI:DI = Size of region to page in bytes
  6355.  
  6356.             Returns
  6357.  
  6358.                  If function was successful:
  6359.                  Carry flag is clear.
  6360.  
  6361.                  If function was not successful:
  6362.                  Carry flag is set.
  6363.  
  6364.             Programmer's Notes
  6365.  
  6366.                  o    If this  function fails  then none  of the  memory
  6367.                       will be relocked.
  6368.                  o    If the specified region overlaps part of a page at
  6369.                       the beginning  or end  of the  region, the page(s)
  6370.                       will be not be relocked.
  6371.  
  6372.  
  6373.  
  6374.  
  6375.  
  6376.  
  6377.  
  6378.  
  6379.  
  6380.  
  6381.  
  6382.  
  6383.  
  6384.  
  6385.  
  6386.  
  6387.  
  6388.  
  6389.  
  6390.  
  6391.  
  6392.  
  6393.  
  6394.  
  6395.  
  6396.  
  6397.  
  6398.  
  6399.  
  6400.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 92
  6401.  
  6402.  
  6403.  
  6404.  
  6405.  
  6406.  
  6407.  
  6408.  
  6409.  
  6410.              14.5 Get Page Size
  6411.  
  6412.  
  6413.                  This function  returns the size of a single memory page
  6414.                  in bytes.
  6415.  
  6416.             To Call
  6417.  
  6418.                  AX = 0604h
  6419.  
  6420.             Returns
  6421.  
  6422.                  If function was successful:
  6423.                  Carry flag is clear
  6424.                  BX:CX = Page size in bytes
  6425.  
  6426.                  If function was not successful:
  6427.                  Carry flag is set
  6428.  
  6429.             Programmers Notes
  6430.  
  6431.                  None
  6432.  
  6433.  
  6434.  
  6435.  
  6436.  
  6437.  
  6438.  
  6439.  
  6440.  
  6441.  
  6442.  
  6443.  
  6444.  
  6445.  
  6446.  
  6447.  
  6448.  
  6449.  
  6450.  
  6451.  
  6452.  
  6453.  
  6454.  
  6455.  
  6456.  
  6457.  
  6458.  
  6459.  
  6460.  
  6461.  
  6462.  
  6463.  
  6464.  
  6465.  
  6466.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 93
  6467.  
  6468.  
  6469.  
  6470.  
  6471.  
  6472.  
  6473.  
  6474.  
  6475.  
  6476.                    15. DEMAND PAGING PERFORMANCE TUNING SERVICES
  6477.  
  6478.  
  6479.             Some applications  will discard  memory objects  or will not
  6480.             access objects for long periods of time.  These services can
  6481.             be used to improve the performance of demand paging.
  6482.  
  6483.             Although  these   functions  are   only  relevant  for  DPMI
  6484.             implementations   that   support   virtual   memory,   other
  6485.             implementations will  ignore these functions (it will always
  6486.             return carry  clear).   Therefore your  code can always call
  6487.             these functions  regardless of the environment it is running
  6488.             under.
  6489.  
  6490.             Since both of these functions are simply advisory functions,
  6491.             the operating  system may  choose to  ignore them.   In  any
  6492.             case,  your  code  should  function  properly  even  if  the
  6493.             functions fail.
  6494.  
  6495.  
  6496.  
  6497.  
  6498.  
  6499.  
  6500.  
  6501.  
  6502.  
  6503.  
  6504.  
  6505.  
  6506.  
  6507.  
  6508.  
  6509.  
  6510.  
  6511.  
  6512.  
  6513.  
  6514.  
  6515.  
  6516.  
  6517.  
  6518.  
  6519.  
  6520.  
  6521.  
  6522.  
  6523.  
  6524.  
  6525.  
  6526.  
  6527.  
  6528.  
  6529.  
  6530.  
  6531.  
  6532.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 94
  6533.  
  6534.  
  6535.  
  6536.  
  6537.  
  6538.  
  6539.  
  6540.  
  6541.  
  6542.              15.1 Reserved Subfunctions
  6543.  
  6544.  
  6545.                  Functions 0700h  and 0701h  are reserved and should not
  6546.                  be called.
  6547.  
  6548.  
  6549.  
  6550.  
  6551.  
  6552.  
  6553.  
  6554.  
  6555.  
  6556.  
  6557.  
  6558.  
  6559.  
  6560.  
  6561.  
  6562.  
  6563.  
  6564.  
  6565.  
  6566.  
  6567.  
  6568.  
  6569.  
  6570.  
  6571.  
  6572.  
  6573.  
  6574.  
  6575.  
  6576.  
  6577.  
  6578.  
  6579.  
  6580.  
  6581.  
  6582.  
  6583.  
  6584.  
  6585.  
  6586.  
  6587.  
  6588.  
  6589.  
  6590.  
  6591.  
  6592.  
  6593.  
  6594.  
  6595.  
  6596.  
  6597.  
  6598.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 95
  6599.  
  6600.  
  6601.  
  6602.  
  6603.  
  6604.  
  6605.  
  6606.  
  6607.  
  6608.              15.2 Mark Page as Demand Paging Candidate
  6609.  
  6610.  
  6611.                  This function  is used  to inform  the operating system
  6612.                  that a  range of  pages should be placed at the head of
  6613.                  the page  out candidate  list.   This will  force these
  6614.                  pages to  be swapped  to disk ahead of other pages even
  6615.                  if the memory has been accessed recently.  However, all
  6616.                  memory contents will be preserved.
  6617.  
  6618.                  This is  useful, for example, if a program knows that a
  6619.                  given piece  of data  will not  be accessed  for a long
  6620.                  period of  time.   That data  is ideal  for swapping to
  6621.                  disk since  the physical  memory it now occupies can be
  6622.                  used for other purposes.
  6623.  
  6624.             To Call
  6625.  
  6626.                  AX = 0702h
  6627.                  BX:CX = Starting linear address of pages to mark
  6628.                  SI:DI = Number of bytes to mark as paging candidates
  6629.  
  6630.             Returns
  6631.  
  6632.                  If function was successful:
  6633.                  Carry flag is clear.
  6634.  
  6635.                  If function was not successful:
  6636.                  Carry flag is set.
  6637.  
  6638.             Programmer's Notes
  6639.  
  6640.                  o    This function  does not  force  the  pages  to  be
  6641.                       swapped to disk immediately.
  6642.                  o    Partial pages will not be discarded.
  6643.  
  6644.  
  6645.  
  6646.  
  6647.  
  6648.  
  6649.  
  6650.  
  6651.  
  6652.  
  6653.  
  6654.  
  6655.  
  6656.  
  6657.  
  6658.  
  6659.  
  6660.  
  6661.  
  6662.  
  6663.  
  6664.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 96
  6665.  
  6666.  
  6667.  
  6668.  
  6669.  
  6670.  
  6671.  
  6672.  
  6673.  
  6674.              15.3 Discard Page Contents
  6675.  
  6676.  
  6677.                  This function  discards the  entire contents of a given
  6678.                  linear memory  range.  It is used after a memory object
  6679.                  that  occupied   a  given  piece  of  memory  has  been
  6680.                  discarded.
  6681.  
  6682.                  The contents  of the  region will be undefined the next
  6683.                  time the  memory is  accessed.   All values  previously
  6684.                  stored in this memory will be lost.
  6685.  
  6686.             To Call
  6687.  
  6688.                  AX = 0703h
  6689.                  BX:CX = Starting linear address of pages to discard
  6690.                  SI:DI = Number of bytes to discard
  6691.  
  6692.             Returns
  6693.  
  6694.                  If function was successful:
  6695.                  Carry flag is clear.
  6696.  
  6697.                  If function was not successful:
  6698.                  Carry flag is set.
  6699.  
  6700.             Programmer's Notes
  6701.  
  6702.                  o    Partial pages will not be discarded.
  6703.  
  6704.  
  6705.  
  6706.  
  6707.  
  6708.  
  6709.  
  6710.  
  6711.  
  6712.  
  6713.  
  6714.  
  6715.  
  6716.  
  6717.  
  6718.  
  6719.  
  6720.  
  6721.  
  6722.  
  6723.  
  6724.  
  6725.  
  6726.  
  6727.  
  6728.  
  6729.  
  6730.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 97
  6731.  
  6732.  
  6733.  
  6734.  
  6735.  
  6736.  
  6737.  
  6738.  
  6739.  
  6740.                             16. PHYSICAL ADDRESS MAPPING
  6741.  
  6742.  
  6743.             Memory mapped  devices such as network adapters and displays
  6744.             sometimes have  memory mapped at physical addresses that lie
  6745.             outside of  the normal  1Mb of memory that is addressable in
  6746.             real  mode.     Under  many  implementations  of  DPMI,  all
  6747.             addresses are  linear addresses  since they  use the  paging
  6748.             mechanism of  the 80386.  This service can be used by device
  6749.             drivers to convert a physical address into a linear address.
  6750.             The linear  address can  then be  used to  access the device
  6751.             memory.
  6752.  
  6753.             Some implementations  of DPMI  may  not  support  this  call
  6754.             because it  could be  used to  circumvent system protection.
  6755.             This call  should only  be used  by programs that absolutely
  6756.             require direct access to a memory mapped device.
  6757.  
  6758.             To Call
  6759.  
  6760.                  AX = 0800h
  6761.                  BX:CX = Physical address of memory
  6762.                  SI:DI = Size of region to map in bytes
  6763.  
  6764.             Returns
  6765.  
  6766.                  If function was successful:
  6767.                  Carry flag is clear.
  6768.                  BX:CX =  Linear address  that can be used to access the
  6769.                       physical memory
  6770.  
  6771.                  If function was not successful:
  6772.                  Carry flag is set.
  6773.  
  6774.             Programmer's Notes
  6775.  
  6776.                  o    Under DPMI  implementations that  do not  use  the
  6777.                       80386 paging  mechanism, the  function will always
  6778.                       succeed and  the address returned will be equal to
  6779.                       the physical  address parameter  passed into  this
  6780.                       function.
  6781.                  o    It is  up to  the caller  to build  an appropriate
  6782.                       selector to access the memory.
  6783.                  o    Do not  use this  service to access memory that is
  6784.                       mapped in the first megabyte of address space (the
  6785.                       real mode addressable region).
  6786.  
  6787.  
  6788.  
  6789.  
  6790.  
  6791.  
  6792.  
  6793.  
  6794.  
  6795.  
  6796.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 98
  6797.  
  6798.  
  6799.  
  6800.  
  6801.  
  6802.  
  6803.  
  6804.  
  6805.  
  6806.                        17. VIRTUAL INTERRUPT STATE FUNCTIONS
  6807.  
  6808.  
  6809.             Under many  implementations of  DPMI, the  interrupt flag in
  6810.             protected mode  will always  be  set  (interrupts  enabled).
  6811.             This is  because the  program is  running under  a protected
  6812.             operating system  that can  not allow  programs  to  disable
  6813.             physical hardware interrupts.  However, the operating system
  6814.             will maintain a "virtual" interrupt state for protected mode
  6815.             programs.   When the program executes a cli instruction, the
  6816.             program's virtual  interrupt state will be disabled, and the
  6817.             program will  not receive  any hardware  interrupts until it
  6818.             executes an  sti to  reenable interrupts  (or calls  service
  6819.             0901h).
  6820.  
  6821.             When a  protected mode program executes a pushf instruction,
  6822.             the real  processor flags  will be  pushed onto  the  stack.
  6823.             Thus, examining  the  flags  pushed  on  the  stack  is  not
  6824.             sufficient to  determine the  state of the program's virtual
  6825.             interrupt flag.   These  services enable programs to get and
  6826.             modify the state of their virtual interrupt flag.
  6827.  
  6828.             The following  sample  code  enters  an  interrupt  critical
  6829.             section and  then restores  the virtual  interrupt state  to
  6830.             it's previous state.
  6831.  
  6832.                  ;
  6833.                  ; Disable interrupts and get previous interrupt state
  6834.                  ;
  6835.                          mov     ax, 0900h
  6836.                          int     31h
  6837.                  ;
  6838.                  ; At this point AX = 0900h or 0901h
  6839.                  ;
  6840.                          .
  6841.                          .
  6842.                          .
  6843.                  ;
  6844.                  ; Restore previous state (assumes AX unchanged)
  6845.                  ;
  6846.                          int     31h
  6847.  
  6848.  
  6849.  
  6850.  
  6851.  
  6852.  
  6853.  
  6854.  
  6855.  
  6856.  
  6857.  
  6858.  
  6859.  
  6860.  
  6861.  
  6862.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9        Page 99
  6863.  
  6864.  
  6865.  
  6866.  
  6867.  
  6868.  
  6869.  
  6870.  
  6871.  
  6872.              17.1 Get and Disable Virtual Interrupt State
  6873.  
  6874.  
  6875.                  This function  will disable  the virtual interrupt flag
  6876.                  and return  the previous state of the virtual interrupt
  6877.                  flag.
  6878.  
  6879.             To Call
  6880.  
  6881.                  AX = 0900h
  6882.  
  6883.             Returns
  6884.  
  6885.                  Carry flag clear (this function always succeeds)
  6886.                  Virtual interrupts are disabled
  6887.                  AL = 0 if virtual interrupts were previously disabled
  6888.                  AL = 1 if virtual interrupts were previously enabled
  6889.  
  6890.             Programmer's Notes
  6891.  
  6892.                  o    AH  will   not  be   changed  by  this  procedure.
  6893.                       Therefore, to  restore the  previous state, simply
  6894.                       execute an Int 31h.
  6895.  
  6896.  
  6897.  
  6898.  
  6899.  
  6900.  
  6901.  
  6902.  
  6903.  
  6904.  
  6905.  
  6906.  
  6907.  
  6908.  
  6909.  
  6910.  
  6911.  
  6912.  
  6913.  
  6914.  
  6915.  
  6916.  
  6917.  
  6918.  
  6919.  
  6920.  
  6921.  
  6922.  
  6923.  
  6924.  
  6925.  
  6926.  
  6927.  
  6928.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 100
  6929.  
  6930.  
  6931.  
  6932.  
  6933.  
  6934.  
  6935.  
  6936.  
  6937.  
  6938.              17.2 Get and Enable Virtual Interrupt State
  6939.  
  6940.  
  6941.                  This function  will enable  the virtual  interrupt flag
  6942.                  and return  the previous state of the virtual interrupt
  6943.                  flag.
  6944.  
  6945.             To Call
  6946.  
  6947.                  AX = 0901h
  6948.  
  6949.             Returns
  6950.  
  6951.                  Carry flag clear (this function always succeeds)
  6952.                  Virtual interrupts are enabled
  6953.                  AL = 0 if virtual interrupts were previously disabled
  6954.                  AL = 1 if virtual interrupts were previously enabled
  6955.  
  6956.             Programmer's Notes
  6957.  
  6958.                  o    AH  will   not  be   changed  by  this  procedure.
  6959.                       Therefore, to  restore the  previous state, simply
  6960.                       execute an Int 31h.
  6961.  
  6962.  
  6963.  
  6964.  
  6965.  
  6966.  
  6967.  
  6968.  
  6969.  
  6970.  
  6971.  
  6972.  
  6973.  
  6974.  
  6975.  
  6976.  
  6977.  
  6978.  
  6979.  
  6980.  
  6981.  
  6982.  
  6983.  
  6984.  
  6985.  
  6986.  
  6987.  
  6988.  
  6989.  
  6990.  
  6991.  
  6992.  
  6993.  
  6994.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 101
  6995.  
  6996.  
  6997.  
  6998.  
  6999.  
  7000.  
  7001.  
  7002.  
  7003.  
  7004.              17.3 Get Virtual Interrupt State
  7005.  
  7006.  
  7007.                  This function  will return  the current  state  of  the
  7008.                  virtual interrupt flag.
  7009.  
  7010.             To Call
  7011.  
  7012.                  AX = 0902h
  7013.  
  7014.             Returns
  7015.  
  7016.                  Carry flag clear (this function always succeeds)
  7017.                  AL = 0 if virtual interrupts are disabled
  7018.                  AL = 1 if virtual interrupts are enabled
  7019.  
  7020.             Programmer's Notes
  7021.  
  7022.                  None
  7023.  
  7024.  
  7025.  
  7026.  
  7027.  
  7028.  
  7029.  
  7030.  
  7031.  
  7032.  
  7033.  
  7034.  
  7035.  
  7036.  
  7037.  
  7038.  
  7039.  
  7040.  
  7041.  
  7042.  
  7043.  
  7044.  
  7045.  
  7046.  
  7047.  
  7048.  
  7049.  
  7050.  
  7051.  
  7052.  
  7053.  
  7054.  
  7055.  
  7056.  
  7057.  
  7058.  
  7059.  
  7060.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 102
  7061.  
  7062.  
  7063.  
  7064.  
  7065.  
  7066.  
  7067.  
  7068.  
  7069.  
  7070.                       18. GET VENDOR SPECIFIC API ENTRY POINT
  7071.  
  7072.  
  7073.             Some DOS extenders provide extensions to the standard set of
  7074.             DPMI calls.   This  call is  used to obtain an address which
  7075.             must be  called to  use the  extensions.   The caller points
  7076.             DS:(E)SI to  a null  terminated string  that  specifies  the
  7077.             vendor name  or some  other unique  identifier to obtain the
  7078.             specific extension entry point.
  7079.  
  7080.             To Call
  7081.  
  7082.                  AX = 0A00h
  7083.                  DS:(E)SI = Pointer to null terminated string
  7084.  
  7085.             Returns
  7086.  
  7087.                  If function was successful:
  7088.                  Carry flag is clear
  7089.                  ES:(E)DI = Extended API entry point
  7090.                  DS, FS,  GS, EAX,  EBX, ECX,  EDX, ESI,  and EBP may be
  7091.             modified
  7092.  
  7093.                  If function was not successful:
  7094.                  Carry flag is set
  7095.  
  7096.             Programmer's Notes
  7097.  
  7098.                  o    Execute a far call to call the API entry point.
  7099.                  o    All extended  API parameters  are specified by the
  7100.                       vendor.
  7101.                  o    The string comparison used to return the API entry
  7102.                       point is case sensitive.
  7103.  
  7104.  
  7105.  
  7106.  
  7107.  
  7108.  
  7109.  
  7110.  
  7111.  
  7112.  
  7113.  
  7114.  
  7115.  
  7116.  
  7117.  
  7118.  
  7119.  
  7120.  
  7121.  
  7122.  
  7123.  
  7124.  
  7125.  
  7126.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 103
  7127.  
  7128.  
  7129.  
  7130.  
  7131.  
  7132.  
  7133.  
  7134.  
  7135.  
  7136.                              19. DEBUG REGISTER SUPPORT
  7137.  
  7138.  
  7139.             The 80386 processor supports special registers that are used
  7140.             for debugging.   Since  the  instructions  to  modify  these
  7141.             registers can only be executed by code running at privileged
  7142.             level  zero,   protected  mode  debuggers  running  in  DPMI
  7143.             environments can  not modify  the registers directly.  These
  7144.             services provide  mechanisms for  setting and clearing debug
  7145.             watchpoints and  detecting when  a watchpoint  has caused  a
  7146.             fault.
  7147.  
  7148.  
  7149.  
  7150.  
  7151.  
  7152.  
  7153.  
  7154.  
  7155.  
  7156.  
  7157.  
  7158.  
  7159.  
  7160.  
  7161.  
  7162.  
  7163.  
  7164.  
  7165.  
  7166.  
  7167.  
  7168.  
  7169.  
  7170.  
  7171.  
  7172.  
  7173.  
  7174.  
  7175.  
  7176.  
  7177.  
  7178.  
  7179.  
  7180.  
  7181.  
  7182.  
  7183.  
  7184.  
  7185.  
  7186.  
  7187.  
  7188.  
  7189.  
  7190.  
  7191.  
  7192.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 104
  7193.  
  7194.  
  7195.  
  7196.  
  7197.  
  7198.  
  7199.  
  7200.  
  7201.  
  7202.              19.1 Set Debug Watchpoint
  7203.  
  7204.  
  7205.                  This  function   will  set  a  debug  watchpoint  at  a
  7206.                  specified linear address.
  7207.  
  7208.             To Call
  7209.  
  7210.                  AX = 0B00h
  7211.                  BX:CX = Linear address of watchpoint
  7212.                  DL = Size of watchpoint (1, 2, or 4)
  7213.                  DH = Type of watchpoint
  7214.                       0 = Execute
  7215.                       1 = Write
  7216.                       2 = Read/Write
  7217.  
  7218.             Returns
  7219.  
  7220.                  If function was successful:
  7221.                  Carry flag is clear
  7222.                  BX = Debug watchpoint handle
  7223.  
  7224.                  If function was not successful:
  7225.                  Carry flag is set
  7226.  
  7227.             Programmer's Notes
  7228.  
  7229.                  None
  7230.  
  7231.  
  7232.  
  7233.  
  7234.  
  7235.  
  7236.  
  7237.  
  7238.  
  7239.  
  7240.  
  7241.  
  7242.  
  7243.  
  7244.  
  7245.  
  7246.  
  7247.  
  7248.  
  7249.  
  7250.  
  7251.  
  7252.  
  7253.  
  7254.  
  7255.  
  7256.  
  7257.  
  7258.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 105
  7259.  
  7260.  
  7261.  
  7262.  
  7263.  
  7264.  
  7265.  
  7266.  
  7267.  
  7268.              19.2 Clear Debug Watchpoint
  7269.  
  7270.  
  7271.                  This function  will clear  a debug  watchpoint that was
  7272.                  set using the Set Debug Watchpoint function.
  7273.  
  7274.             To Call
  7275.  
  7276.                  AX = 0B01h
  7277.                  BX = Debug watchpoint handle
  7278.  
  7279.             Returns
  7280.  
  7281.                  If function was successful:
  7282.                  Carry flag is clear
  7283.  
  7284.                  If function was not successful:
  7285.                  Carry flag is set
  7286.  
  7287.             Programmer's Notes
  7288.  
  7289.                  o    This call frees the debug watchpoint handle
  7290.  
  7291.  
  7292.  
  7293.  
  7294.  
  7295.  
  7296.  
  7297.  
  7298.  
  7299.  
  7300.  
  7301.  
  7302.  
  7303.  
  7304.  
  7305.  
  7306.  
  7307.  
  7308.  
  7309.  
  7310.  
  7311.  
  7312.  
  7313.  
  7314.  
  7315.  
  7316.  
  7317.  
  7318.  
  7319.  
  7320.  
  7321.  
  7322.  
  7323.  
  7324.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 106
  7325.  
  7326.  
  7327.  
  7328.  
  7329.  
  7330.  
  7331.  
  7332.  
  7333.  
  7334.              19.3 Get State of Debug Watchpoint
  7335.  
  7336.  
  7337.                  This function  returns the  state of a debug watchpoint
  7338.                  that was set using the Set Debug Watchpoint function.
  7339.  
  7340.             To Call
  7341.  
  7342.                  AX = 0B02h
  7343.                  BX = Debug Watchpoint Handle
  7344.  
  7345.             Returns
  7346.  
  7347.                  If function was successful:
  7348.                  Carry flag is clear
  7349.                  AX = Status flags
  7350.                       Bit 0 = 1 if watch point has been executed
  7351.  
  7352.                  If function was not successful:
  7353.                  Carry flag is set
  7354.  
  7355.             Programmer's Notes
  7356.  
  7357.                  o    To clear  the watchpoint state the caller must use
  7358.                       function 0B03h.
  7359.  
  7360.  
  7361.  
  7362.  
  7363.  
  7364.  
  7365.  
  7366.  
  7367.  
  7368.  
  7369.  
  7370.  
  7371.  
  7372.  
  7373.  
  7374.  
  7375.  
  7376.  
  7377.  
  7378.  
  7379.  
  7380.  
  7381.  
  7382.  
  7383.  
  7384.  
  7385.  
  7386.  
  7387.  
  7388.  
  7389.  
  7390.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 107
  7391.  
  7392.  
  7393.  
  7394.  
  7395.  
  7396.  
  7397.  
  7398.  
  7399.  
  7400.              19.4 Reset Debug Watchpoint
  7401.  
  7402.  
  7403.                  This function  resets the state of a previously defined
  7404.                  debug watchpoint.
  7405.  
  7406.             To Call
  7407.  
  7408.                  AX = 0B03h
  7409.                  BX = Debug Watchpoint Handle
  7410.  
  7411.             Returns
  7412.  
  7413.                  If function was successful:
  7414.                  Carry flag is clear
  7415.  
  7416.                  If function was not successful:
  7417.                  Carry flag is set
  7418.  
  7419.             Programmer's Notes
  7420.  
  7421.                  None
  7422.  
  7423.  
  7424.  
  7425.  
  7426.  
  7427.  
  7428.  
  7429.  
  7430.  
  7431.  
  7432.  
  7433.  
  7434.  
  7435.  
  7436.  
  7437.  
  7438.  
  7439.  
  7440.  
  7441.  
  7442.  
  7443.  
  7444.  
  7445.  
  7446.  
  7447.  
  7448.  
  7449.  
  7450.  
  7451.  
  7452.  
  7453.  
  7454.  
  7455.  
  7456.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 108
  7457.  
  7458.  
  7459.  
  7460.  
  7461.  
  7462.  
  7463.  
  7464.  
  7465.  
  7466.                                    20. OTHER APIS
  7467.  
  7468.  
  7469.             In general,  any software  interrupt interface  that  passes
  7470.             parameters in  the EAX,  EBX, ECX,  EDX, ESI,  EDI, and  EBP
  7471.             registers will  work  as  long  as  none  of  the  registers
  7472.             contains a  segment value.   In  other words,  if a software
  7473.             interrupt interface is completely register based without any
  7474.             pointers, segment  register, or  stack parameters,  that API
  7475.             could work under any DPMI implementation.
  7476.  
  7477.             More complex  APIs require the caller to use the translation
  7478.             services described on page 58.
  7479.  
  7480.  
  7481.  
  7482.  
  7483.  
  7484.  
  7485.  
  7486.  
  7487.  
  7488.  
  7489.  
  7490.  
  7491.  
  7492.  
  7493.  
  7494.  
  7495.  
  7496.  
  7497.  
  7498.  
  7499.  
  7500.  
  7501.  
  7502.  
  7503.  
  7504.  
  7505.  
  7506.  
  7507.  
  7508.  
  7509.  
  7510.  
  7511.  
  7512.  
  7513.  
  7514.  
  7515.  
  7516.  
  7517.  
  7518.  
  7519.  
  7520.  
  7521.  
  7522.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 109
  7523.  
  7524.  
  7525.  
  7526.  
  7527.  
  7528.  
  7529.  
  7530.  
  7531.  
  7532.                             21. NOTES FOR DOS EXTENDERS
  7533.  
  7534.  
  7535.             Many programs  that use  DPMI will be bound to DOS extenders
  7536.             so that  they will be able to run under any DOS environment.
  7537.             Existing DOS extenders support APIs that differ from the Int
  7538.             31h interface.   Usually,  DOS  extenders  use  an  Int  21h
  7539.             multiplex for their extended APIs.
  7540.  
  7541.             Extenders  that   support  DPMI   will  need  to  initialize
  7542.             differently when they are run under DPMI environments.  They
  7543.             will need  to enter  protected mode  using the  DPMI real to
  7544.             protected mode  entry point, install their own API handlers,
  7545.             and then load the DOS extended application program.
  7546.  
  7547.  
  7548.  
  7549.  
  7550.  
  7551.  
  7552.  
  7553.  
  7554.  
  7555.  
  7556.  
  7557.  
  7558.  
  7559.  
  7560.  
  7561.  
  7562.  
  7563.  
  7564.  
  7565.  
  7566.  
  7567.  
  7568.  
  7569.  
  7570.  
  7571.  
  7572.  
  7573.  
  7574.  
  7575.  
  7576.  
  7577.  
  7578.  
  7579.  
  7580.  
  7581.  
  7582.  
  7583.  
  7584.  
  7585.  
  7586.  
  7587.  
  7588.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 110
  7589.  
  7590.  
  7591.  
  7592.  
  7593.  
  7594.  
  7595.  
  7596.  
  7597.  
  7598.              21.1 Initialization of  Extenders
  7599.  
  7600.  
  7601.             DOS extenders  should check  for the presence of DPMI before
  7602.             attempting to  allocate memory or enter protected mode using
  7603.             any other  API.   DOS extenders should check for APIs in the
  7604.             following order:
  7605.  
  7606.                  DOS Protected Mode Interface
  7607.                  Virtual Control Program Interface
  7608.                  eXtended Memory Specification
  7609.                  Int 15h memory allocation
  7610.  
  7611.             When DPMI  services are  detected,  extenders  that  provide
  7612.             interfaces that  extend or are different from the basic DPMI
  7613.             interface will switch into protected mode and initialize any
  7614.             internal data  structures.   DPMI compatible  extenders that
  7615.             provide  no   API  extensions   should  simply  execute  the
  7616.             protected mode application in real mode.
  7617.  
  7618.  
  7619.  
  7620.  
  7621.              21.2 Installing API Extensions
  7622.  
  7623.  
  7624.             DOS  extenders  typically  use  Int  21h  to  implement  API
  7625.             extensions.  Under DPMI, a DOS extender will need to install
  7626.             an API  translation library  by hooking Int 21h via then get
  7627.             and set  protected mode interrupt vector functions (see page
  7628.             56).   The DOS  extender library  then gets to see every DOS
  7629.             call executed  by the  application program.  If the API does
  7630.             not have any pointers then the interrupt can be reflected to
  7631.             the original  interrupt handler.   The  default handler will
  7632.             pass the  interrupt  to  real  mode.    Other  APIs  can  be
  7633.             explicitly mapped by the DOS extender.
  7634.  
  7635.             WARNING:   The translation  library code should be in locked
  7636.             memory to  prevent page  faults while  DOS is  in a critical
  7637.             section.   This could  happen, for  instance, if  a  program
  7638.             called DOS reentrantly from an Int 24h (critical error).
  7639.  
  7640.  
  7641.  
  7642.  
  7643.              21.3 Loading the Application Program
  7644.  
  7645.  
  7646.             Once the  API translation  library has been initialized, the
  7647.             DOS extender can load the application program using standard
  7648.             DOS calls.  Memory should be allocated using the DPMI memory
  7649.             allocation services.
  7650.  
  7651.  
  7652.  
  7653.  
  7654.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 111
  7655.  
  7656.  
  7657.  
  7658.  
  7659.  
  7660.  
  7661.  
  7662.  
  7663.  
  7664.              21.4 Providing API Extensions
  7665.  
  7666.  
  7667.             DPMI call  0A00h provides a standard mechanism for providing
  7668.             vendor specific extensions to the standard APIs.  To support
  7669.             extensions under a DPMI environment, the translation library
  7670.             should hook  the Int 31h chain (using the DOS get/set vector
  7671.             calls) and  watch for  call 0A00h.  When this call is issued
  7672.             with the  proper string  parameter, the  Int 31h  hook  code
  7673.             should modify  ES:(E)DI, clear  the carry flag on the stack,
  7674.             and iret  without passing  the call  down the Int 31h chain.
  7675.             If  the  string  passed  in  ES:(E)DI  does  not  match  the
  7676.             extensions supported  by the library then the call should be
  7677.             passed down the Int 31h chain.
  7678.  
  7679.  
  7680.  
  7681.  
  7682.  
  7683.  
  7684.  
  7685.  
  7686.  
  7687.  
  7688.  
  7689.  
  7690.  
  7691.  
  7692.  
  7693.  
  7694.  
  7695.  
  7696.  
  7697.  
  7698.  
  7699.  
  7700.  
  7701.  
  7702.  
  7703.  
  7704.  
  7705.  
  7706.  
  7707.  
  7708.  
  7709.  
  7710.  
  7711.  
  7712.  
  7713.  
  7714.  
  7715.  
  7716.  
  7717.  
  7718.  
  7719.  
  7720.      July 26, 1990 DOS PROTECTED MODE INTERFACE SPECIFICATION 0.9       Page 112
  7721.  
  7722.  
  7723.